diff options
author | Jim Meyering <jim@meyering.net> | 1994-10-26 12:55:54 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 1994-10-26 12:55:54 +0000 |
commit | 41640fd22de6bd90cee0e0ea344296ca8c5efc07 (patch) | |
tree | de25de0dc68b503d184eb03e02ee2e8e50769eaa | |
parent | aa479d24ea619ee9218b05bd7da871983c74b3e1 (diff) | |
download | gnulib-41640fd22de6bd90cee0e0ea344296ca8c5efc07.tar.gz |
GNU shell utilitiesSHELLUTILS-1_10x
-rw-r--r-- | lib/xmalloc.c | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/lib/xmalloc.c b/lib/xmalloc.c index 0a4ad4f35d..9f701111bb 100644 --- a/lib/xmalloc.c +++ b/lib/xmalloc.c @@ -49,6 +49,20 @@ void error (int, int, const char *, ...); void error (); #endif +static VOID * +fixup_null_alloc (n) + size_t n; +{ + VOID *p; + + p = 0; + if (n == 0) + p = malloc ((size_t) 1); + if (p == 0) + error (xmalloc_exit_failure, 0, "memory exhausted"); + return p; +} + /* Allocate N bytes of memory dynamically, with error checking. */ VOID * @@ -59,14 +73,13 @@ xmalloc (n) p = malloc (n); if (p == 0) - error (xmalloc_exit_failure, 0, "memory exhausted"); + p = fixup_null_alloc (n); return p; } /* Change the size of an allocated block of memory P to N bytes, with error checking. - If P is NULL, run xmalloc. - If N is 0, run free and return NULL. */ + If P is NULL, run xmalloc. */ VOID * xrealloc (p, n) @@ -75,13 +88,8 @@ xrealloc (p, n) { if (p == 0) return xmalloc (n); - if (n == 0) - { - free (p); - return 0; - } p = realloc (p, n); if (p == 0) - error (xmalloc_exit_failure, 0, "memory exhausted"); + p = fixup_null_alloc (n); return p; } |