projects
/
oweals
/
busybox.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
ec23c49
)
Allow xrealloc to act as a free() when size=0, per SuS2.
author
Eric Andersen
<andersen@codepoet.org>
Thu, 28 Jun 2001 21:22:19 +0000
(21:22 -0000)
committer
Eric Andersen
<andersen@codepoet.org>
Thu, 28 Jun 2001 21:22:19 +0000
(21:22 -0000)
-Erik
libbb/xfuncs.c
patch
|
blob
|
history
diff --git
a/libbb/xfuncs.c
b/libbb/xfuncs.c
index f3b294be2ad0592eb2f0d1059590dc712b567c02..eb93bf139d617a3950870cf98737a0e3b0ebb87a 100644
(file)
--- a/
libbb/xfuncs.c
+++ b/
libbb/xfuncs.c
@@
-44,7
+44,17
@@
extern void *xmalloc(size_t size)
extern void *xrealloc(void *old, size_t size)
{
- void *ptr = realloc(old, size);
+ void *ptr;
+
+ /* SuS2 says "If size is 0 and ptr is not a null pointer, the
+ * object pointed to is freed." Do that here, in case realloc
+ * returns a NULL, since we don't want to choke in that case. */
+ if (size==0 && old) {
+ free(old);
+ return NULL;
+ }
+
+ ptr = realloc(old, size);
if (!ptr)
error_msg_and_die(memory_exhausted);
return ptr;