From: David Carlton <carlton@math.stanford.edu>
To: Daniel Jacobowitz <drow@mvista.com>
Cc: gdb-patches@sources.redhat.com, ezannoni@redhat.com
Subject: Re: RFA: Correct field names for class methods
Date: Wed, 28 Aug 2002 11:50:00 -0000 [thread overview]
Message-ID: <ro1k7mahm3b.fsf@jackfruit.Stanford.EDU> (raw)
In-Reply-To: <20020828173429.GA5873@nevyn.them.org>
In article <20020828173429.GA5873@nevyn.them.org>, Daniel Jacobowitz
<drow@mvista.com> writes:
> On Wed, Aug 28, 2002 at 10:23:06AM -0700, David Carlton wrote:
>> In article <20020827031346.GA16591@nevyn.them.org>, Daniel Jacobowitz
>> <drow@mvista.com> writes:
>> > +void
>> > +update_method_name_from_physname (char **old_name, char *physname)
>> > +{
>> > + char *method_name;
>> > +
>> > + method_name = method_name_from_physname (physname);
>> > +
>> > + if (method_name == NULL)
>> > + error ("bad physname %s\n", physname);
>> > +
>> > + if (strcmp (*old_name, method_name) != 0)
>> > + *old_name = method_name;
>> > + else
>> > + xfree (method_name);
>> > +}
>>
>> I'm pretty sure this is a memory leak. How about replacing the last
>> if clause by
>>
>> xfree(*old_name);
>> *old_name = method_name;
>>
>> That should get rid of the memory leak and avoid a superfluous
>> strcmp.
> No can do. Look at where TYPE_NAME is allocated; sometimes (often?
> Not sure.) it is on the obstack.
Eek! I hadn't followed all the code paths. Unfortunate.
Having said that, update_method_name_from_physname() is called in
exactly one place, with the first argument equal to the location of
new_fnlist->fn_fieldlist.name, and at that point in the code, that
points to main_fn_name, which is always allocated using xmalloc().
It's only on other code paths that new_fnlist->fn_fieldlist.name gets
allocated on an obstack.
So I think my fix would be safe with the code as is, but future users
of the update_method_name_from_physname() would have to be careful.
So it seems that either my fix should be applied with a comment added
to the definition of update_method_name_from_physname() saying not to
call it unless it's safe to xfree() the first argument, or else it
should be left your way, but perhaps with a FIXME comment added. I
have no idea which one of those would be better.
(Or, now that I think about it, maybe the fix is for main_fn_name to
be allocated on an obstack, and for update_method_name_from_physname()
also to use an obstack. Hmm.)
David Carlton
carlton@math.stanford.edu
next prev parent reply other threads:[~2002-08-28 18:36 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-08-26 20:30 Daniel Jacobowitz
2002-08-28 10:26 ` David Carlton
2002-08-28 11:36 ` Daniel Jacobowitz
2002-08-28 11:50 ` David Carlton [this message]
2002-08-29 21:07 ` Jim Blandy
2002-08-30 0:14 ` Daniel Jacobowitz
2002-09-09 16:32 ` Elena Zannoni
2002-09-10 9:49 ` Daniel Jacobowitz
2002-09-10 15:15 ` Elena Zannoni
2002-09-10 15:20 ` Daniel Jacobowitz
2002-09-13 11:30 ` Elena Zannoni
2002-09-13 19:11 ` Daniel Jacobowitz
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=ro1k7mahm3b.fsf@jackfruit.Stanford.EDU \
--to=carlton@math.stanford.edu \
--cc=drow@mvista.com \
--cc=ezannoni@redhat.com \
--cc=gdb-patches@sources.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