This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH] mtrace: properly handle realloc (p, 0)
- From: Andreas Schwab <schwab at linux-m68k dot org>
- To: libc-alpha at sourceware dot org
- Date: Wed, 02 Jan 2013 18:03:04 +0100
- Subject: [PATCH] mtrace: properly handle realloc (p, 0)
realloc (p, 0) is equivalent to (free (p), 0) if p != 0.
Andreas.
[BZ #14981]
* malloc/mtrace.c (tr_reallochook): If realloc returns NULL when
size is zero, record memory as freed.
---
malloc/mtrace.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/malloc/mtrace.c b/malloc/mtrace.c
index 3f02c71..87b35ec 100644
--- a/malloc/mtrace.c
+++ b/malloc/mtrace.c
@@ -219,8 +219,13 @@ tr_reallochook (ptr, size, caller)
tr_where (caller, info);
if (hdr == NULL)
- /* Failed realloc. */
- fprintf (mallstream, "! %p %#lx\n", ptr, (unsigned long int) size);
+ {
+ if (size != 0)
+ /* Failed realloc. */
+ fprintf (mallstream, "! %p %#lx\n", ptr, (unsigned long int) size);
+ else
+ fprintf (mallstream, "- %p\n", ptr);
+ }
else if (ptr == NULL)
fprintf (mallstream, "+ %p %#lx\n", hdr, (unsigned long int) size);
else
--
1.8.1
--
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."