Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@redhat.com>
To: Joel Brobecker <brobecker@adacore.com>
Cc: gdb-patches@sourceware.org
Subject: Re: RFA: fix PR 9350
Date: Wed, 07 Jan 2009 14:49:00 -0000	[thread overview]
Message-ID: <m3vdsr5fzz.fsf@fleche.redhat.com> (raw)
In-Reply-To: <20090107083448.GJ3664@adacore.com> (Joel Brobecker's message of "Wed\, 7 Jan 2009 12\:34\:48 +0400")

>>>>> "Joel" == Joel Brobecker <brobecker@adacore.com> writes:

Joel> This is actually something that I learnt only relatively recently,
Joel> maybe a year or two ago: If you put something on the cleanup queue,
Joel> you should perform the cleanup when you're done, or you run
Joel> the risk of having a memory leak.

Yeah.  Yesterday I was contemplating writing a gcc plugin to detect
this error.  But back to reality...

Joel> Do we have a different scenario in your example that causes
Joel> a memory leak?

Yeah, this patch reveals a number of leak styles.

In syms_from_objfile, we installed a cleanup but then discarded it.
This is another cleanup oddity -- because they are handled linearly,
code must either be careful to create them in the right order so that
a sequence of discard_ and do_ calls can be run at the end; or the
code must duplicate the action.

In update_global_location_list, we simply were not installing any
cleanup for the local VEC.

In varobj_invalidate, the freeing was only done on one branch of an
`if', though the condition of the `if' unconditionally allocated
memory.

>> -      do_cleanups (ui_out_chain);
>> +      do_cleanups (old_chain);

Joel> Ooops, does it look like you're using uiout after it has been
Joel> deleted?  (I have seen the same issue a few more time later
Joel> in your patch)

No, it just looks that way because ui_out_chain had a funny name.

The old code looked like:

-      ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");

So ui_out_chain was just used for finalizing a tuple.
`uiout' itself is still valid; the additional cleanup we run (via
`old_chain') is to finalize `stb'.

Joel> Perhaps this function would benefit from having only one place
Joel> where the result is returned, thus requiring only one call to
Joel> do_cleanups? At first sight, it seems relatively easy to achieve
Joel> in this case. That's an open question - I'm fine with just fixing
Joel> the above by moving the do_cleanups to just before the return.

I only did it this way because it was the prevailing style in the
function.  I will switch it and retest and resubmit.

Tom


  reply	other threads:[~2009-01-07 14:49 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-07  1:08 Tom Tromey
2009-01-07  8:35 ` Joel Brobecker
2009-01-07 14:49   ` Tom Tromey [this message]
2009-01-07 16:18     ` Tom Tromey
2009-01-08  9:27       ` Joel Brobecker
2009-01-08 16:33         ` Tom Tromey

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=m3vdsr5fzz.fsf@fleche.redhat.com \
    --to=tromey@redhat.com \
    --cc=brobecker@adacore.com \
    --cc=gdb-patches@sourceware.org \
    /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