[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] date: free allocated memory to fix Valgrind warning
From: |
Eric Blake |
Subject: |
Re: [PATCH] date: free allocated memory to fix Valgrind warning |
Date: |
Tue, 16 Feb 2016 09:00:42 -0700 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.0 |
On 02/16/2016 06:42 AM, Daniel Lockyer wrote:
> When running Valgrind to monitor ./src/date, it reports the variable `tz`
> isn't freed when the program exits. I simply added a `free(tz)` call
> to clean this up.
> ---
> src/date.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/src/date.c b/src/date.c
> index 3670553..23eef87 100644
> --- 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.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature