This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] mtrace: properly handle realloc (p, 0)


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?


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]