diff options
author | mckusick <mckusick@FreeBSD.org> | 2010-04-28 05:33:59 +0000 |
---|---|---|
committer | mckusick <mckusick@FreeBSD.org> | 2010-04-28 05:33:59 +0000 |
commit | 3a0f5972a0de87aebef1af257922515700da4217 (patch) | |
tree | a65d36ab57a1e076de7e7a1d78add642fbd7062e /lib/libc/stdlib/reallocf.c | |
parent | f40c3a9dc50f808e512fcc9f9f738717013b483b (diff) | |
parent | a768cbcadec7189b9947e9f3cde39fe806bbc1d7 (diff) | |
download | FreeBSD-src-3a0f5972a0de87aebef1af257922515700da4217.zip FreeBSD-src-3a0f5972a0de87aebef1af257922515700da4217.tar.gz |
Update to current version of head.
Diffstat (limited to 'lib/libc/stdlib/reallocf.c')
-rw-r--r-- | lib/libc/stdlib/reallocf.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/libc/stdlib/reallocf.c b/lib/libc/stdlib/reallocf.c index 5320926..a85b5a3 100644 --- a/lib/libc/stdlib/reallocf.c +++ b/lib/libc/stdlib/reallocf.c @@ -35,7 +35,14 @@ reallocf(void *ptr, size_t size) void *nptr; nptr = realloc(ptr, size); - if (!nptr && ptr) + + /* + * When the System V compatibility option (malloc "V" flag) is + * in effect, realloc(ptr, 0) frees the memory and returns NULL. + * So, to avoid double free, call free() only when size != 0. + * realloc(ptr, 0) can't fail when ptr != NULL. + */ + if (!nptr && ptr && size != 0) free(ptr); return (nptr); } |