This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [RFA] readelf.c (process_gnu_liblist): Stop memory leak.
- From: Richard Sandiford <richard dot sandiford at linaro dot org>
- To: Michael Snyder <msnyder at vmware dot com>
- Cc: "binutils\ at sourceware dot org" <binutils at sourceware dot org>
- Date: Mon, 14 Mar 2011 12:17:47 +0000
- Subject: Re: [RFA] readelf.c (process_gnu_liblist): Stop memory leak.
- References: <4D758990.7080000@vmware.com>
Michael Snyder <msnyder@vmware.com> writes:
> OK?
>
> 2011-03-07 Michael Snyder <msnyder@msnyder-server.eng.vmware.com>
>
> * readelf.c (process_gnu_liblist): Stop memory leak.
>
> Index: readelf.c
> ===================================================================
> RCS file: /cvs/src/src/binutils/readelf.c,v
> retrieving revision 1.534
> diff -u -p -r1.534 readelf.c
> --- readelf.c 1 Mar 2011 00:02:32 -0000 1.534
> +++ readelf.c 8 Mar 2011 01:27:07 -0000
> @@ -11807,7 +11811,7 @@ process_gnu_liblist (FILE * file)
> Elf_Internal_Shdr * section;
> Elf_Internal_Shdr * string_sec;
> Elf32_External_Lib * elib;
> - char * strtab;
> + char * strtab = NULL;
> size_t strtab_size;
> size_t cnt;
> unsigned i;
> @@ -11833,6 +11837,7 @@ process_gnu_liblist (FILE * file)
> break;
> string_sec = section_headers + section->sh_link;
>
> + free (strtab);
> strtab = (char *) get_data (NULL, file, string_sec->sh_offset, 1,
> string_sec->sh_size,
> _("liblist string table"));
> @@ -11886,6 +11891,7 @@ process_gnu_liblist (FILE * file)
> }
> }
>
> + free (strtab);
> return 1;
> }
Why not simply free strtab at the same time as elib? That version
is preapproved, if it works.
Richard