diff options
| author | andersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2001-06-28 21:22:19 +0000 |
|---|---|---|
| committer | andersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2001-06-28 21:22:19 +0000 |
| commit | 51a00c8aaa470cc5fa5f944200138ff746acce75 (patch) | |
| tree | 89a4cdbbe7166132ff8bf9559ce914c4ccec81dc | |
| parent | 9c7e60dfcfa89dfa77044bc334b0b26902b6251d (diff) | |
| download | busybox-w32-51a00c8aaa470cc5fa5f944200138ff746acce75.tar.gz busybox-w32-51a00c8aaa470cc5fa5f944200138ff746acce75.tar.bz2 busybox-w32-51a00c8aaa470cc5fa5f944200138ff746acce75.zip | |
Allow xrealloc to act as a free() when size=0, per SuS2.
-Erik
git-svn-id: svn://busybox.net/trunk/busybox@2945 69ca8d6d-28ef-0310-b511-8ec308f3f277
| -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; |
