Commit 013e8479 authored by Max Kellermann's avatar Max Kellermann

AudioCompress: abort on out-of-memory

This library crashes on out-of-memory (NULL pointer dereference). There's not much useful MPD can do in such a situation, so let's explicitly abort instead, just like GLib does.
parent 27535a7f
...@@ -33,6 +33,9 @@ struct Compressor { ...@@ -33,6 +33,9 @@ struct Compressor {
struct Compressor *Compressor_new(unsigned int history) struct Compressor *Compressor_new(unsigned int history)
{ {
struct Compressor *obj = malloc(sizeof(struct Compressor)); struct Compressor *obj = malloc(sizeof(struct Compressor));
if (obj == NULL)
/* out of memory, not much we can do */
abort();
obj->prefs.target = TARGET; obj->prefs.target = TARGET;
obj->prefs.maxgain = GAINMAX; obj->prefs.maxgain = GAINMAX;
...@@ -61,6 +64,10 @@ void Compressor_delete(struct Compressor *obj) ...@@ -61,6 +64,10 @@ void Compressor_delete(struct Compressor *obj)
static int *resizeArray(int *data, int newsz, int oldsz) static int *resizeArray(int *data, int newsz, int oldsz)
{ {
data = realloc(data, newsz*sizeof(int)); data = realloc(data, newsz*sizeof(int));
if (data == NULL)
/* out of memory, not much we can do */
abort();
if (newsz > oldsz) if (newsz > oldsz)
memset(data + oldsz, 0, sizeof(int)*(newsz - oldsz)); memset(data + oldsz, 0, sizeof(int)*(newsz - oldsz));
return data; return data;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment