From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15364 invoked by alias); 28 Aug 2008 22:14:20 -0000 Received: (qmail 15354 invoked by uid 22791); 28 Aug 2008 22:14:19 -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; Thu, 28 Aug 2008 22:13:36 +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 m7SMCxn8004075 for ; Thu, 28 Aug 2008 18:13:19 -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 m7SMCmLk014700 for ; Thu, 28 Aug 2008 18:12:48 -0400 Received: from opsy.redhat.com (vpn-10-46.bos.redhat.com [10.16.10.46]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id m7SMCg3h003985; Thu, 28 Aug 2008 18:12:42 -0400 Received: by opsy.redhat.com (Postfix, from userid 500) id 54A61508204; Thu, 28 Aug 2008 16:12:53 -0600 (MDT) To: gdb-patches@sourceware.org Subject: RFA: fix memory leak in dwarf2read.c From: Tom Tromey Reply-To: Tom Tromey X-Attribution: Tom Date: Thu, 28 Aug 2008 22:14:00 -0000 Message-ID: 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/msg00655.txt.bz2 I found a memory leak while looking at dwarf2read. We xstrdup the directory name, but nothing ever frees it. The simplest fix seemed to be to allocate it on the objfile obstack. Built and regtested on x86-64 (compile farm). I also verified this, before and after, with valgrind. Ok? Tom :ADDPATCH dwarf: 2008-08-28 Tom Tromey * dwarf2read.c (dwarf2_build_psymtabs_hard): Copy dirname on obstack. diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index 5cb444e..95a85b1 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -1529,7 +1529,9 @@ dwarf2_build_psymtabs_hard (struct objfile *objfile, int mainline) objfile->static_psymbols.next); if (comp_unit_die.dirname) - pst->dirname = xstrdup (comp_unit_die.dirname); + pst->dirname = obsavestring (comp_unit_die.dirname, + strlen (comp_unit_die.dirname), + &objfile->objfile_obstack); pst->read_symtab_private = (char *) this_cu;