aboutsummaryrefslogtreecommitdiffstats
path: root/src/sllist.c
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/sllist.c
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 '')
-rw-r--r--src/sllist.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/sllist.c b/src/sllist.c
index e87be6ad5..9d581ef5d 100644
--- a/src/sllist.c
+++ b/src/sllist.c
@@ -30,14 +30,14 @@ static void init_strnode(struct strnode *x, char *s)
struct strnode *new_strnode(char *s)
{
- struct strnode *x = malloc(sizeof(struct strnode));
+ struct strnode *x = xmalloc(sizeof(struct strnode));
init_strnode(x, s);
return x;
}
struct strnode *new_strnode_dup(char *s, const size_t size)
{
- struct strnode *x = malloc(sizeof(struct strnode) + size);
+ struct strnode *x = xmalloc(sizeof(struct strnode) + size);
x->next = NULL;
x->data = ((char *)x + sizeof(struct strnode));
memcpy((void *)x->data, (void*)s, size);
@@ -46,7 +46,7 @@ struct strnode *new_strnode_dup(char *s, const size_t size)
struct sllnode *new_sllnode(void *s, const size_t size)
{
- struct sllnode *x = malloc(sizeof(struct sllnode) + size);
+ struct sllnode *x = xmalloc(sizeof(struct sllnode) + size);
x->next = NULL;
x->size = size;
x->data = ((char *)x + sizeof(struct sllnode));