aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils.c')
-rw-r--r--src/utils.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/utils.c b/src/utils.c
index 60fa3f135..919553d3e 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -133,13 +133,14 @@ mpd_malloc void *xmalloc(size_t size)
mpd_malloc void *xrealloc(void *ptr, size_t size)
{
- void *ret;
+ void *ret = realloc(ptr, size);
- /* hmm... realloc to 0 isn't uncommon..., is it? this check
- * may be too extreme... (eric) */
- assert((mpd_likely(size)));
+ /* some C libraries return NULL when size == 0,
+ * make sure we get a free()-able pointer (free(NULL)
+ * doesn't work with all C libraries, either) */
+ if (mpd_unlikely(!ret && !size))
+ ret = realloc(ptr, 1);
- ret = realloc(ptr, size);
if (mpd_unlikely(!ret))
FATAL("OOM: realloc\n");
return ret;