aboutsummaryrefslogtreecommitdiffstats
path: root/src/audioOutputs
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2006-08-26 06:25:57 +0000
committerEric Wong <normalperson@yhbt.net>2006-08-26 06:25:57 +0000
commit90847fc8818836a296e9d500725c0eb154a4d3c5 (patch)
tree2c1f9d1c294749045c4462ad43baeee1a5aee815 /src/audioOutputs
parentbe554c2596c8d7f905e25a67b60f4497c76d4d9f (diff)
downloadmpd-90847fc8818836a296e9d500725c0eb154a4d3c5.tar.gz
mpd-90847fc8818836a296e9d500725c0eb154a4d3c5.tar.xz
mpd-90847fc8818836a296e9d500725c0eb154a4d3c5.zip
Replace strdup and {c,re,m}alloc with x* variants to check for OOM errors
I'm checking for zero-size allocations and assert()-ing them, so we can more easily get backtraces and debug problems, but we'll also allow -DNDEBUG people to live on the edge if they wish. We do not rely on errno when checking for OOM errors because some implementations of malloc do not set it, and malloc is commonly overridden by userspace wrappers. I've spent some time looking through the source and didn't find any obvious places where we would explicitly allocate 0 bytes, so we shouldn't trip any of those assertions. We also avoid allocating zero bytes because C libraries don't handle this consistently (some return NULL, some not); and it's dangerous either way. git-svn-id: https://svn.musicpd.org/mpd/trunk@4690 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to 'src/audioOutputs')
-rw-r--r--src/audioOutputs/audioOutput_alsa.c6
-rw-r--r--src/audioOutputs/audioOutput_ao.c6
-rw-r--r--src/audioOutputs/audioOutput_mvp.c2
-rw-r--r--src/audioOutputs/audioOutput_oss.c10
-rw-r--r--src/audioOutputs/audioOutput_osx.c4
-rw-r--r--src/audioOutputs/audioOutput_pulse.c6
-rw-r--r--src/audioOutputs/audioOutput_shout.c2
7 files changed, 18 insertions, 18 deletions
diff --git a/src/audioOutputs/audioOutput_alsa.c b/src/audioOutputs/audioOutput_alsa.c
index 31601b37c..85872c09a 100644
--- a/src/audioOutputs/audioOutput_alsa.c
+++ b/src/audioOutputs/audioOutput_alsa.c
@@ -59,7 +59,7 @@ typedef struct _AlsaData {
static AlsaData *newAlsaData(void)
{
- AlsaData *ret = malloc(sizeof(AlsaData));
+ AlsaData *ret = xmalloc(sizeof(AlsaData));
ret->device = NULL;
ret->pcmHandle = NULL;
@@ -85,7 +85,7 @@ static int alsa_initDriver(AudioOutput * audioOutput, ConfigParam * param)
if (param) {
BlockParam *bp = getBlockParam(param, "device");
- ad->device = bp ? strdup(bp->value) : strdup("default");
+ ad->device = bp ? xstrdup(bp->value) : xstrdup("default");
if ((bp = getBlockParam(param, "use_mmap")) &&
(!strcasecmp(bp->value, "yes") ||
@@ -96,7 +96,7 @@ static int alsa_initDriver(AudioOutput * audioOutput, ConfigParam * param)
if ((bp = getBlockParam(param, "period_time")))
ad->period_time = atoi(bp->value);
} else
- ad->device = strdup("default");
+ ad->device = xstrdup("default");
audioOutput->data = ad;
return 0;
diff --git a/src/audioOutputs/audioOutput_ao.c b/src/audioOutputs/audioOutput_ao.c
index e94a6e6b7..bf4b99a34 100644
--- a/src/audioOutputs/audioOutput_ao.c
+++ b/src/audioOutputs/audioOutput_ao.c
@@ -40,7 +40,7 @@ typedef struct _AoData {
static AoData *newAoData(void)
{
- AoData *ret = malloc(sizeof(AoData));
+ AoData *ret = xmalloc(sizeof(AoData));
ret->device = NULL;
ret->options = NULL;
@@ -112,9 +112,9 @@ static int audioOutputAo_initDriver(AudioOutput * audioOutput,
blockParam = getBlockParam(param, "options");
if (blockParam) {
- dup = strdup(blockParam->value);
+ dup = xstrdup(blockParam->value);
} else
- dup = strdup("");
+ dup = xstrdup("");
if (strlen(dup)) {
stk1 = NULL;
diff --git a/src/audioOutputs/audioOutput_mvp.c b/src/audioOutputs/audioOutput_mvp.c
index b82b0a5b7..65116681a 100644
--- a/src/audioOutputs/audioOutput_mvp.c
+++ b/src/audioOutputs/audioOutput_mvp.c
@@ -109,7 +109,7 @@ static int mvp_testDefault(void)
static int mvp_initDriver(AudioOutput * audioOutput, ConfigParam * param)
{
- MvpData *md = malloc(sizeof(MvpData));
+ MvpData *md = xmalloc(sizeof(MvpData));
md->fd = -1;
audioOutput->data = md;
diff --git a/src/audioOutputs/audioOutput_oss.c b/src/audioOutputs/audioOutput_oss.c
index bd66bb050..ddb1b1788 100644
--- a/src/audioOutputs/audioOutput_oss.c
+++ b/src/audioOutputs/audioOutput_oss.c
@@ -164,7 +164,7 @@ static void addSupportedParam(OssData * od, int param, int val)
int index = getIndexForParam(param);
od->numSupported[index]++;
- od->supported[index] = realloc(od->supported[index],
+ od->supported[index] = xrealloc(od->supported[index],
od->numSupported[index] * sizeof(int));
od->supported[index][od->numSupported[index] - 1] = val;
}
@@ -174,7 +174,7 @@ static void addUnsupportedParam(OssData * od, int param, int val)
int index = getIndexForParam(param);
od->numUnsupported[index]++;
- od->unsupported[index] = realloc(od->unsupported[index],
+ od->unsupported[index] = xrealloc(od->unsupported[index],
od->numUnsupported[index] *
sizeof(int));
od->unsupported[index][od->numUnsupported[index] - 1] = val;
@@ -193,7 +193,7 @@ static void removeSupportedParam(OssData * od, int param, int val)
}
od->numSupported[index]--;
- od->supported[index] = realloc(od->supported[index],
+ od->supported[index] = xrealloc(od->supported[index],
od->numSupported[index] * sizeof(int));
}
@@ -210,7 +210,7 @@ static void removeUnsupportedParam(OssData * od, int param, int val)
}
od->numUnsupported[index]--;
- od->unsupported[index] = realloc(od->unsupported[index],
+ od->unsupported[index] = xrealloc(od->unsupported[index],
od->numUnsupported[index] *
sizeof(int));
}
@@ -254,7 +254,7 @@ static void unsupportParam(OssData * od, int param, int val)
static OssData *newOssData(void)
{
- OssData *ret = malloc(sizeof(OssData));
+ OssData *ret = xmalloc(sizeof(OssData));
ret->device = NULL;
ret->fd = -1;
diff --git a/src/audioOutputs/audioOutput_osx.c b/src/audioOutputs/audioOutput_osx.c
index d386bcbfc..439aefab3 100644
--- a/src/audioOutputs/audioOutput_osx.c
+++ b/src/audioOutputs/audioOutput_osx.c
@@ -40,7 +40,7 @@ typedef struct _OsxData {
static OsxData *newOsxData()
{
- OsxData *ret = malloc(sizeof(OsxData));
+ OsxData *ret = xmalloc(sizeof(OsxData));
pthread_mutex_init(&ret->mutex, NULL);
pthread_cond_init(&ret->condition, NULL);
@@ -284,7 +284,7 @@ static int osx_openDevice(AudioOutput * audioOutput)
/* create a buffer of 1s */
od->bufferSize = (audioFormat->sampleRate) *
(audioFormat->bits >> 3) * (audioFormat->channels);
- od->buffer = realloc(od->buffer, od->bufferSize);
+ od->buffer = xrealloc(od->buffer, od->bufferSize);
od->pos = 0;
od->len = 0;
diff --git a/src/audioOutputs/audioOutput_pulse.c b/src/audioOutputs/audioOutput_pulse.c
index d7c544cfe..3dade76b6 100644
--- a/src/audioOutputs/audioOutput_pulse.c
+++ b/src/audioOutputs/audioOutput_pulse.c
@@ -46,7 +46,7 @@ static PulseData *newPulseData(void)
{
PulseData *ret;
- ret = malloc(sizeof(PulseData));
+ ret = xmalloc(sizeof(PulseData));
ret->s = NULL;
ret->server = NULL;
@@ -78,8 +78,8 @@ static int pulse_initDriver(AudioOutput * audioOutput, ConfigParam * param)
}
pd = newPulseData();
- pd->server = server ? strdup(server->value) : NULL;
- pd->sink = sink ? strdup(sink->value) : NULL;
+ pd->server = server ? xstrdup(server->value) : NULL;
+ pd->sink = sink ? xstrdup(sink->value) : NULL;
audioOutput->data = pd;
return 0;
diff --git a/src/audioOutputs/audioOutput_shout.c b/src/audioOutputs/audioOutput_shout.c
index 5c268930a..2cf2ba624 100644
--- a/src/audioOutputs/audioOutput_shout.c
+++ b/src/audioOutputs/audioOutput_shout.c
@@ -74,7 +74,7 @@ typedef struct _ShoutData {
static ShoutData *newShoutData(void)
{
- ShoutData *ret = malloc(sizeof(ShoutData));
+ ShoutData *ret = xmalloc(sizeof(ShoutData));
ret->shoutConn = shout_new();
ret->opened = 0;