diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2004-11-17 23:09:12 +0000 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2004-11-17 23:09:12 +0000 |
commit | 0884570c4e81073738a5bdceb2653f447685a296 (patch) | |
tree | e67af1d8445f34b494a125e6d6c87cb5d61669c3 /lib/realloc.c | |
parent | a18a5093f84d0ef20711af85b7ce0b9392144f27 (diff) | |
download | coreutils-0884570c4e81073738a5bdceb2653f447685a296.tar.xz |
Sync from gnulib.
Diffstat (limited to 'lib/realloc.c')
-rw-r--r-- | lib/realloc.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/lib/realloc.c b/lib/realloc.c index ccbf99138..14fec075f 100644 --- a/lib/realloc.c +++ b/lib/realloc.c @@ -1,5 +1,5 @@ -/* Work around bug on some systems where realloc (NULL, 0) fails. - Copyright (C) 1997, 2003 Free Software Foundation, Inc. +/* realloc() function that is glibc compatible. + Copyright (C) 1997, 2003, 2004 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -32,8 +32,15 @@ void * rpl_realloc (void *p, size_t n) { if (n == 0) - n = 1; - if (p == 0) + { + n = 1; + + /* In theory realloc might fail, so don't rely on it to free. */ + free (p); + p = NULL; + } + + if (p == NULL) return malloc (n); return realloc (p, n); } |