diff options
| author | Jaakko Heinonen <jh@FreeBSD.org> | 2010-08-02 09:13:09 +0000 |
|---|---|---|
| committer | Jaakko Heinonen <jh@FreeBSD.org> | 2010-08-02 09:13:09 +0000 |
| commit | 85cf033c8c4a710edc2d0e84a8e3c382e95592d4 (patch) | |
| tree | 63e9c48f4b885d7877f652ad9fc281eb98acef48 /lib/libc | |
| parent | ffccb45f5095c3c853a23242b699da2430edafa9 (diff) | |
Notes
Diffstat (limited to 'lib/libc')
| -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 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); } |
