From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24726 invoked by alias); 17 Aug 2008 17:40:30 -0000 Received: (qmail 24710 invoked by uid 22791); 17 Aug 2008 17:40:28 -0000 X-Spam-Check-By: sourceware.org Received: from mx2.redhat.com (HELO mx2.redhat.com) (66.187.237.31) by sourceware.org (qpsmtpd/0.31) with ESMTP; Sun, 17 Aug 2008 17:39:32 +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 m7HHcsqI024399 for ; Sun, 17 Aug 2008 13:39:15 -0400 Received: from opsy.redhat.com (vpn-10-34.bos.redhat.com [10.16.10.34]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id m7HHcgSi013485; Sun, 17 Aug 2008 13:38:42 -0400 Received: by opsy.redhat.com (Postfix, from userid 500) id E138B37831C; Sun, 17 Aug 2008 11:35:19 -0600 (MDT) To: gdb-patches@sourceware.org Subject: RFA: fix memory leak in copy_type_recursive From: Tom Tromey Reply-To: Tom Tromey X-Attribution: Tom Date: Sun, 17 Aug 2008 17:40:00 -0000 Message-ID: User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (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: 2008-08/txt/msg00461.txt.bz2 While reading about types recently, I ran across a memory leak in copy_type_recursive. copy_type_recursive enters copied types into a hash table. The hash table is allocated with a NULL 'del_f' function -- so entries are never freed. However, copy_type_recursive allocates entries using xmalloc. This patch fixes the bug by allocating the hash table entry on the objfile's obstack. This is ok because this is how the hash table itself is allocated. Built & regtested on x86-64 (compile farm). Ok? Tom 2008-08-17 Tom Tromey * gdbtypes.c (copy_type_recursive): Allocate 'stored' on objfile's obstack. diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index 939a1dc..bbacee5 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -2928,7 +2928,7 @@ copy_type_recursive (struct objfile *objfile, /* We must add the new type to the hash table immediately, in case we encounter this type again during a recursive call below. */ - stored = xmalloc (sizeof (struct type_pair)); + stored = obstack_alloc (&objfile->objfile_obstack, sizeof (struct type_pair)); stored->old = type; stored->new = new_type; *slot = stored;