From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26061 invoked by alias); 19 Feb 2004 22:19:36 -0000 Mailing-List: contact gdb-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sources.redhat.com Received: (qmail 15507 invoked from network); 19 Feb 2004 21:56:11 -0000 Received: from unknown (HELO localhost.redhat.com) (216.129.200.20) by sources.redhat.com with SMTP; 19 Feb 2004 21:56:11 -0000 Received: from gnu.org (localhost [127.0.0.1]) by localhost.redhat.com (Postfix) with ESMTP id A985A2B92; Thu, 19 Feb 2004 16:56:07 -0500 (EST) Message-ID: <403530F7.4090609@gnu.org> Date: Thu, 19 Feb 2004 22:19:00 -0000 From: Andrew Cagney User-Agent: Mozilla/5.0 (X11; U; NetBSD macppc; en-US; rv:1.4.1) Gecko/20040217 MIME-Version: 1.0 To: da_gdb@egenera.com Cc: Daniel Jacobowitz , gdb@sources.redhat.com Subject: Re: execute_control_command may not remove its cleanups References: <1077204518.1305.1192.camel@hasufel.egenera.com> <20040219154016.GA24829@nevyn.them.org> <1077214912.1304.1351.camel@hasufel.egenera.com> <20040219184730.GA26281@nevyn.them.org> <1077217836.1304.1361.camel@hasufel.egenera.com> In-Reply-To: <1077217836.1304.1361.camel@hasufel.egenera.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-SW-Source: 2004-02/txt/msg00254.txt.bz2 Dave, > Ok. I see your point. How about setting old_chain to cleanup_chain > unconditionally at the beginning of the function and doing the cleanups > unconditionally at the end? That way, we're safe against both > scenarios: against doing cleanups prematurely, but also safe against > getting into the function with cleanup_chain null and then freeing > something random at a later point. FYI, that is one of the ways recommended in the doco: > The first style is try/finally. Before it exits, your code-block calls > @code{do_cleanups} with the old cleanup chain and thus ensures that your > code-block's cleanups are always performed. For instance, the following > code-segment avoids a memory leak problem (even when @code{error} is > called and a forced stack unwind occurs) by ensuring that the > @code{xfree} will always be called: > > @smallexample > struct cleanup *old = make_cleanup (null_cleanup, 0); > data = xmalloc (sizeof blah); > make_cleanup (xfree, data); > ... blah blah ... > do_cleanups (old); > @end smallexample The main reason why the the code you're studying doesn't match the doco is because it pre-dates that said doco :-( Andrew