From patchwork Fri Jan 20 21:46:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 63537 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0C29B3887F79 for ; Fri, 20 Jan 2023 21:48:40 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from outbound-ss-820.bluehost.com (outbound-ss-820.bluehost.com [69.89.24.241]) by sourceware.org (Postfix) with ESMTPS id 092C13857400 for ; Fri, 20 Jan 2023 21:46:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 092C13857400 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com Received: from cmgw12.mail.unifiedlayer.com (unknown [10.0.90.127]) by progateway2.mail.pro1.eigbox.com (Postfix) with ESMTP id 8087610046B5D for ; Fri, 20 Jan 2023 21:46:42 +0000 (UTC) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTP id IzDep9971iOW0IzDepygGG; Fri, 20 Jan 2023 21:46:42 +0000 X-Authority-Reason: nr=8 X-Authority-Analysis: v=2.4 cv=S5kcfKgP c=1 sm=1 tr=0 ts=63cb0bc2 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=RvmDmJFTN0MA:10:nop_rcvd_month_year a=Qbun_eYptAEA:10:endurance_base64_authed_username_1 a=ihFeAXQEJiG3-ZByjdkA:9 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=hJ9g+J1zb30HJoFXgc/MYwjp1rHIDhHIoJkOkGG8tyk=; b=sCYeR3fue5txITJPQn6PhLrecA 5nQAwlBVhUCOemkzlMiSAU41vZkcOBREp8jz5Mj2g+dmq3uM9LBiZak7v6aPfmipGVIm24Qs5iP/W 1CXyAFjsfhGyBZBVLjPS8LeI7; Received: from 97-122-76-186.hlrn.qwest.net ([97.122.76.186]:60144 helo=localhost.localdomain) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1pIzDe-001GNx-5R; Fri, 20 Jan 2023 14:46:42 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 22/27] Fix memory leak in mdebugread.c Date: Fri, 20 Jan 2023 14:46:13 -0700 Message-Id: <20230120214618.3236224-23-tom@tromey.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230120214618.3236224-1-tom@tromey.com> References: <20230120214618.3236224-1-tom@tromey.com> MIME-Version: 1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 97.122.76.186 X-Source-L: No X-Exim-ID: 1pIzDe-001GNx-5R X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-76-186.hlrn.qwest.net (localhost.localdomain) [97.122.76.186]:60144 X-Source-Auth: tom+tromey.com X-Email-Count: 23 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3027.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" mdebugread.c allocates blocks on the heap. However, this is a memory leak if the corresponding objfile is ever destroyed. This patch changes this code to use allocate_block instead, fixing a FIXME from 2003. I don't know how to test this patch. --- gdb/mdebugread.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c index 7fa25ae3183..b6a0b3c07df 100644 --- a/gdb/mdebugread.c +++ b/gdb/mdebugread.c @@ -236,7 +236,8 @@ static struct type *new_type (char *); enum block_type { FUNCTION_BLOCK, NON_FUNCTION_BLOCK }; -static struct block *new_block (enum block_type, enum language); +static struct block *new_block (struct objfile *objfile, + enum block_type, enum language); static struct compunit_symtab *new_symtab (const char *, int, struct objfile *); @@ -794,7 +795,7 @@ parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend, s->type ()->set_is_prototyped (true); /* Create and enter a new lexical context. */ - b = new_block (FUNCTION_BLOCK, s->language ()); + b = new_block (objfile, FUNCTION_BLOCK, s->language ()); s->set_value_block (b); b->set_function (s); b->set_start (sh->value); @@ -1125,7 +1126,7 @@ parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend, } top_stack->blocktype = stBlock; - b = new_block (NON_FUNCTION_BLOCK, psymtab_language); + b = new_block (objfile, NON_FUNCTION_BLOCK, psymtab_language); b->set_start (sh->value + top_stack->procadr); b->set_superblock (top_stack->cur_block); top_stack->cur_block = b; @@ -4622,8 +4623,8 @@ new_symtab (const char *name, int maxlines, struct objfile *objfile) /* All symtabs must have at least two blocks. */ bv = new_bvect (2); - bv->set_block (GLOBAL_BLOCK, new_block (NON_FUNCTION_BLOCK, lang)); - bv->set_block (STATIC_BLOCK, new_block (NON_FUNCTION_BLOCK, lang)); + bv->set_block (GLOBAL_BLOCK, new_block (objfile, NON_FUNCTION_BLOCK, lang)); + bv->set_block (STATIC_BLOCK, new_block (objfile, NON_FUNCTION_BLOCK, lang)); bv->static_block ()->set_superblock (bv->global_block ()); cust->set_blockvector (bv); @@ -4710,12 +4711,10 @@ new_bvect (int nblocks) linearly; otherwise, store them hashed. */ static struct block * -new_block (enum block_type type, enum language language) +new_block (struct objfile *objfile, enum block_type type, + enum language language) { - /* FIXME: carlton/2003-09-11: This should use allocate_block to - allocate the block. Which, in turn, suggests that the block - should be allocated on an obstack. */ - struct block *retval = XCNEW (struct block); + struct block *retval = allocate_block (&objfile->objfile_obstack); if (type == FUNCTION_BLOCK) retval->set_multidict (mdict_create_linear_expandable (language));