summaryrefslogtreecommitdiff
path: root/lib/libc
diff options
context:
space:
mode:
authorJaakko Heinonen <jh@FreeBSD.org>2010-08-02 09:13:09 +0000
committerJaakko Heinonen <jh@FreeBSD.org>2010-08-02 09:13:09 +0000
commit85cf033c8c4a710edc2d0e84a8e3c382e95592d4 (patch)
tree63e9c48f4b885d7877f652ad9fc281eb98acef48 /lib/libc
parentffccb45f5095c3c853a23242b699da2430edafa9 (diff)
Notes
Diffstat (limited to 'lib/libc')
-rw-r--r--lib/libc/stdlib/reallocf.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/libc/stdlib/reallocf.c b/lib/libc/stdlib/reallocf.c
index 5320926ce4bc..a85b5a3c036b 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);
}