diff options
author | Eric Andersen <andersen@codepoet.org> | 2001-06-28 21:22:19 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2001-06-28 21:22:19 +0000 |
commit | 029b4a04221794101812407f5c60155bdfdd1481 (patch) | |
tree | 89a4cdbbe7166132ff8bf9559ce914c4ccec81dc | |
parent | ec23c4920f0c4ba6854a4fb62497fe9519f79361 (diff) | |
download | busybox-w32-029b4a04221794101812407f5c60155bdfdd1481.tar.gz busybox-w32-029b4a04221794101812407f5c60155bdfdd1481.tar.bz2 busybox-w32-029b4a04221794101812407f5c60155bdfdd1481.zip |
Allow xrealloc to act as a free() when size=0, per SuS2.
-Erik
-rw-r--r-- | libbb/xfuncs.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c index f3b294be2..eb93bf139 100644 --- a/libbb/xfuncs.c +++ b/libbb/xfuncs.c | |||
@@ -44,7 +44,17 @@ extern void *xmalloc(size_t size) | |||
44 | 44 | ||
45 | extern void *xrealloc(void *old, size_t size) | 45 | extern void *xrealloc(void *old, size_t size) |
46 | { | 46 | { |
47 | void *ptr = realloc(old, size); | 47 | void *ptr; |
48 | |||
49 | /* SuS2 says "If size is 0 and ptr is not a null pointer, the | ||
50 | * object pointed to is freed." Do that here, in case realloc | ||
51 | * returns a NULL, since we don't want to choke in that case. */ | ||
52 | if (size==0 && old) { | ||
53 | free(old); | ||
54 | return NULL; | ||
55 | } | ||
56 | |||
57 | ptr = realloc(old, size); | ||
48 | if (!ptr) | 58 | if (!ptr) |
49 | error_msg_and_die(memory_exhausted); | 59 | error_msg_and_die(memory_exhausted); |
50 | return ptr; | 60 | return ptr; |