[Andrew Pimlott <pimlott@abel.MATH.HARVARD.EDU>] realloc(p, 0) vs. free
Andreas Jaeger
aj@arthur.rhein-neckar.de
Wed Apr 28 09:55:00 GMT 1999
Hi,
Andrew reported the appended problem and accoring to Unix98 realloc
(p,0) should free the pointer p but we don't do.
ISO C 9X defines realloc (ptr,0) as:
If size is zero and ptr is not a null pointer, the object it
points to is freed.
malloc.c has the following comment:
/*
REALLOC_ZERO_BYTES_FREES should be set if a call to
realloc with zero bytes should be the same as a call to free.
Some people think it should. Otherwise, since this malloc
returns a unique pointer for malloc(0), so does realloc(p, 0).
*/
and REALLOC_ZERO_BYTES_FREES is not set with glibc2.
Btw. malloc (0) is defined by Unix98 as:
If the size of the space requested is 0, the behaviour is
implementation-dependent; the value returned will be either a null
pointer or a unique pointer.
I'm in favor of defining REALLOC_ZERO_BYTES_FREES to follow
Unix98/ISO C9x.
Andreas
1999-04-28 Andreas Jaeger <aj@arthur.rhein-neckar.de>
* malloc/malloc.c (REALLOC_ZERO_BYTES_FREES): Define it to follow
ISO C9x and Unix98.
--- malloc/malloc.c.~1~ Wed Feb 24 18:50:16 1999
+++ malloc/malloc.c Wed Apr 28 18:53:02 1999
@@ -1,5 +1,5 @@
/* Malloc implementation for multiple threads without lock contention.
- Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc.
+ Copyright (C) 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Wolfram Gloger <wmglo@dent.med.uni-muenchen.de>
and Doug Lea <dl@cs.oswego.edu>, 1996.
@@ -373,7 +373,7 @@
*/
-/* #define REALLOC_ZERO_BYTES_FREES */
+#define REALLOC_ZERO_BYTES_FREES
/*
More information about the Libc-alpha
mailing list