Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Michael Snyder <msnyder@vmware.com>
To: Jan Kratochvil <jan.kratochvil@redhat.com>
Cc: "gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
Subject: Re: [rfa] add_symbol_file_command, avoid memory leak.
Date: Sun, 27 Feb 2011 20:42:00 -0000	[thread overview]
Message-ID: <4D6AB5A2.3030807@vmware.com> (raw)
In-Reply-To: <20110227171301.GA16297@host1.dyn.jankratochvil.net>

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.


  reply	other threads:[~2011-02-27 20:35 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-27  1:56 Michael Snyder
2011-02-27 20:35 ` Jan Kratochvil
2011-02-27 20:42   ` Michael Snyder [this message]
2011-02-27 20:51     ` Jan Kratochvil
2011-02-27 22:00       ` Michael Snyder
2011-02-27 22:12         ` Jan Kratochvil

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4D6AB5A2.3030807@vmware.com \
    --to=msnyder@vmware.com \
    --cc=gdb-patches@sourceware.org \
    --cc=jan.kratochvil@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox