svn commit: r211919 - stable/7/lib/libc/stdlib
Jaakko Heinonen
jh at FreeBSD.org
Sat Aug 28 06:33:01 UTC 2010
Author: jh
Date: Sat Aug 28 06:33:01 2010
New Revision: 211919
URL: http://svn.freebsd.org/changeset/base/211919
Log:
MFC r204636:
In reallocf(3), free the memory only when size != 0. Otherwise, when the
System V compatibility option (malloc "V" flag) is in effect a zero sized
reallocf() could cause a double free.
PR: bin/141753
Modified:
stable/7/lib/libc/stdlib/reallocf.c
Directory Properties:
stable/7/lib/libc/ (props changed)
stable/7/lib/libc/stdtime/ (props changed)
Modified: stable/7/lib/libc/stdlib/reallocf.c
==============================================================================
--- stable/7/lib/libc/stdlib/reallocf.c Sat Aug 28 06:31:15 2010 (r211918)
+++ stable/7/lib/libc/stdlib/reallocf.c Sat Aug 28 06:33:01 2010 (r211919)
@@ -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);
}
More information about the svn-src-stable-7
mailing list