coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] date: free allocated memory to fix Valgrind warning


From: Daniel Lockyer
Subject: Re: [PATCH] date: free allocated memory to fix Valgrind warning
Date: Tue, 16 Feb 2016 20:53:23 +0000

Thanks for the advice Eric, I'll take it into account next time.

Great, thanks Berny.

Regards,
Daniel

On Tue, Feb 16, 2016 at 05:57:21PM +0100, Bernhard Voelker wrote:
> On 02/16/2016 05:00 PM, Eric Blake wrote:
> > On 02/16/2016 06:42 AM, Daniel Lockyer wrote:
> >> --- a/src/date.c
> >> +++ b/src/date.c
> >> @@ -548,6 +548,8 @@ main (int argc, char **argv)
> >>        ok &= show_date (format, when, tz);
> >>      }
> >>
> >> +  free(tz);
> >> +
> >>    return ok ? EXIT_SUCCESS : EXIT_FAILURE;
> >>  }
> > 
> > Memory is going to be freed anyway by virtue of exiting; leaving
> > something allocated is actually faster than freeing it. We typically
> > mark code like this addition inside IF_LINT() so that it is only
> > compiled to shut up valgrind, but intentionally omitted when we don't
> > care about the leak.
> 
> Right, so I'll push the attached in Daniel's name soon.
> Please note that I changed 'free' to 'tzfree' for correctness.
> 
> Have a nice day,
> Berny

> From 587a1ba5df564eaea26c0bc5f5f31a934e4424b3 Mon Sep 17 00:00:00 2001
> From: Daniel Lockyer <address@hidden>
> Date: Tue, 16 Feb 2016 17:52:07 +0100
> Subject: [PATCH] date: free timezone variable to avoid valgrind warning
> 
> * src/date.c (main): Free TZ variable to pacify valgrind, guarded
> by IF_LINT.
> ---
>  src/date.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/src/date.c b/src/date.c
> index 3670553..269570b 100644
> --- a/src/date.c
> +++ b/src/date.c
> @@ -548,6 +548,8 @@ main (int argc, char **argv)
>        ok &= show_date (format, when, tz);
>      }
>  
> +  IF_LINT (tzfree (tz));
> +
>    return ok ? EXIT_SUCCESS : EXIT_FAILURE;
>  }
>  
> -- 
> 2.1.4
> 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]