[rfa] add_symbol_file_command, avoid memory leak.

Michael Snyder msnyder@vmware.com
Sun Feb 27 20:42:00 GMT 2011


Jan Kratochvil wrote:
> On Sun, 27 Feb 2011 02:38:04 +0100, Michael Snyder wrote:
>> This looks straightforward, but I'd appreciate review.
>> I don't really understand why sect_opts never gets freed?
> 
> It is a bug, sect_opts should be freed.  It is last time used by the lines:
>       char *val = sect_opts[i].value;
>       char *sec = sect_opts[i].name;
> 
> The strings in sect_opts[i].name are last time used there by:
>   symbol_file_add (filename, from_tty ? SYMFILE_VERBOSE : 0,
>                    section_addrs, flags);
> 
> This is also the reason why the NAMEs do not have strdup() and they get safely
> freed through make_cleanup_freeargv there.
> 
> 
>> --- symfile.c	26 Feb 2011 02:07:09 -0000	1.307
>> +++ symfile.c	27 Feb 2011 01:35:32 -0000
>> @@ -2169,15 +2169,15 @@ add_symbol_file_command (char *args, int
>>    size_t num_sect_opts = 0;
>>    struct cleanup *my_cleanups = make_cleanup (null_cleanup, NULL);
>>  
>> +  if (args == NULL)
>> +    error (_("add-symbol-file takes a file name and an address"));
>> +
>>    num_sect_opts = 16;
>>    sect_opts = (struct sect_opt *) xmalloc (num_sect_opts
>>  					   * sizeof (struct sect_opt));
>>  
>>    dont_repeat ();
>>  
>> -  if (args == NULL)
>> -    error (_("add-symbol-file takes a file name and an address"));
>> -
>>    argv = gdb_buildargv (args);
>>    make_cleanup_freeargv (argv);
>>  
> 
> While a nitpick it is a regression, that dont_repeat should be called even in
> the case of that error.


No, it's a fix.  I moved the error before dont_repeat.



More information about the Gdb-patches mailing list