From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6090 invoked by alias); 13 Apr 2009 12:44:04 -0000 Received: (qmail 6081 invoked by uid 22791); 13 Apr 2009 12:44:03 -0000 X-SWARE-Spam-Status: No, hits=-2.4 required=5.0 tests=AWL,BAYES_00,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; Mon, 13 Apr 2009 12:43:59 +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 n3DChvUo005230 for ; Mon, 13 Apr 2009 08:43:57 -0400 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 n3DChx8p023961 for ; Mon, 13 Apr 2009 08:43:59 -0400 Received: from host0.dyn.jankratochvil.net (sebastian-int.corp.redhat.com [172.16.52.221]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n3DChurs002798 for ; Mon, 13 Apr 2009 08:43:57 -0400 Received: from host0.dyn.jankratochvil.net (localhost [127.0.0.1]) by host0.dyn.jankratochvil.net (8.14.3/8.14.3) with ESMTP id n3DChsVN015903 for ; Mon, 13 Apr 2009 14:43:55 +0200 Received: (from jkratoch@localhost) by host0.dyn.jankratochvil.net (8.14.3/8.14.2/Submit) id n3DChsGo015901 for gdb-patches@sourceware.org; Mon, 13 Apr 2009 14:43:54 +0200 Date: Mon, 13 Apr 2009 12:44:00 -0000 From: Jan Kratochvil To: gdb-patches@sourceware.org Subject: Re: [patch] [5/5] Types reference counting [value_history_cleanup] Message-ID: <20090413124354.GA13859@host0.dyn.jankratochvil.net> References: <20090411102237.GF32624@host0.dyn.jankratochvil.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20090411102237.GF32624@host0.dyn.jankratochvil.net> User-Agent: Mutt/1.5.18 (2008-05-17) X-IsSubscribed: yes 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-04/txt/msg00231.txt.bz2 On Sat, 11 Apr 2009 12:22:37 +0200, Jan Kratochvil wrote: > this patch brings no new functionality. It could be enabled only during some > --enable-debug builds but there is currently no such configure option. > > Found it caught some bugs during the development (by trying to double-free some > types). It can be also used to verify there are no types leaks. There is now a fix to free anything at all. When the function was written there was an older implementation of type_decref which was incorrectly freeing the zero-reference-count types immediately (and not just on the garbage collection by free_all_types). gdb/ 2009-04-13 Jan Kratochvil * value.c (value_history_cleanup): New function. (_initialize_values): Setup a value_history_cleanup final call. diff --git a/gdb/value.c b/gdb/value.c index 76ba93b..c5df1d3 100644 --- a/gdb/value.c +++ b/gdb/value.c @@ -861,6 +861,29 @@ show_values (char *num_exp, int from_tty) num_exp[1] = '\0'; } } + +/* Sanity check for memory leaks and proper types reference counting. */ + +static void +value_history_cleanup (void *unused) +{ + while (value_history_chain) + { + struct value_history_chunk *chunk = value_history_chain; + int i; + + for (i = 0; i < ARRAY_SIZE (chunk->values); i++) + value_free (chunk->values[i]); + + value_history_chain = chunk->next; + xfree (chunk); + } + value_history_count = 0; + + /* Free the unreferenced types above. */ + free_all_values (); + free_all_types (); +} /* Internal variables. These are variables within the debugger that hold values assigned by debugger commands. @@ -2071,4 +2094,6 @@ Placeholder command for showing help on convenience functions."), TYPE_CODE (internal_fn_type) = TYPE_CODE_INTERNAL_FUNCTION; TYPE_LENGTH (internal_fn_type) = sizeof (struct internal_function *); TYPE_NAME (internal_fn_type) = ""; + + make_final_cleanup (value_history_cleanup, NULL); } -- 1.6.0.6