[RFA] readelf.c (process_gnu_liblist): Stop memory leak.

Michael Snyder msnyder@vmware.com
Mon Mar 14 21:14:00 GMT 2011


Michael Snyder wrote:
> Richard Sandiford wrote:
>> 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.
> 
> I have no test for it.  Found by static analysis.
> 

... and the testsuite doesn't seem to exercise it.




More information about the Binutils mailing list