From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14095 invoked by alias); 7 Jan 2009 14:49:06 -0000 Received: (qmail 14085 invoked by uid 22791); 7 Jan 2009 14:49:05 -0000 X-SWARE-Spam-Status: No, hits=-2.1 required=5.0 tests=AWL,BAYES_00,KAM_MX,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: sourceware.org Received: from mx2.redhat.com (HELO mx2.redhat.com) (66.187.237.31) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 07 Jan 2009 14:48:58 +0000 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n07EmaPr005634; Wed, 7 Jan 2009 09:48:36 -0500 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n07EmaAN002172; Wed, 7 Jan 2009 09:48:36 -0500 Received: from opsy.redhat.com (vpn-12-46.rdu.redhat.com [10.11.12.46]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n07EmZRr018558; Wed, 7 Jan 2009 09:48:35 -0500 Received: by opsy.redhat.com (Postfix, from userid 500) id 782B3378095; Wed, 7 Jan 2009 07:48:33 -0700 (MST) To: Joel Brobecker Cc: gdb-patches@sourceware.org Subject: Re: RFA: fix PR 9350 References: <20090107083448.GJ3664@adacore.com> From: Tom Tromey Reply-To: Tom Tromey Date: Wed, 07 Jan 2009 14:49:00 -0000 In-Reply-To: <20090107083448.GJ3664@adacore.com> (Joel Brobecker's message of "Wed\, 7 Jan 2009 12\:34\:48 +0400") Message-ID: User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2009-01/txt/msg00098.txt.bz2 >>>>> "Joel" == Joel Brobecker 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