This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] mtrace: properly handle realloc (p, 0)
- From: KOSAKI Motohiro <kosaki dot motohiro at gmail dot com>
- To: Andreas Schwab <schwab at linux-m68k dot org>
- Cc: libc-alpha <libc-alpha at sourceware dot org>
- Date: Wed, 2 Jan 2013 12:18:47 -0500
- Subject: Re: [PATCH] mtrace: properly handle realloc (p, 0)
- References: <m2bod734c7.fsf@igel.home>
On Wed, Jan 2, 2013 at 12:03 PM, Andreas Schwab <schwab@linux-m68k.org> wrote:
> 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
Please correct me if I misunderstand something. realloc (p, 0)
behavior is an implementation defined and your code seems depend on
glibc malloc. So it is
a chance to make a regression if users uses another malloc or nested malloc
hook. right?