utils.c: fix xrealloc
(based on suggested patch by Jan-Benedict Glaw): > While hacking mpd, I noticed that an assert()ion in xrealloc is wrong. > A null size is perfectly legal, so we shouldn't assert on that. Since some C libraries return NULL when size == 0, we'll make sure we get a free()-able pointer since some of those C libraries also barf on free(NULL). git-svn-id: https://svn.musicpd.org/mpd/trunk@4740 09075e82-0dd4-0310-85a5-a0d7c8717e4f
This commit is contained in:
parent
12d253118d
commit
f5c7f3da31
11
src/utils.c
11
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;
|
||||
|
Loading…
Reference in New Issue
Block a user