From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id kRyLGbV0+mhT2wQAWB0awg (envelope-from ) for ; Thu, 23 Oct 2025 14:32:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simark.ca; s=mail; t=1761244341; bh=x0h4RaXr8IgrMoM8GWqvNBaRWuvskaC6MawieVI+d9Y=; h=Date:Subject:To:References:From:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=MaOokogQel7InEZgSHR8jDCMM8+/LXA2wVV4WMUzkN+/lTZPeQeY4A+e+9mR3GSWZ f++VY1wekKaFI3Hl1tOfM7P5A7sCQDh3NF2YoWk1bNM+qV1vwfzVyrDxvV1bXiMdZu 6sjk0FTUFDZxSsyA9imOIHsfw5IiQtyFldMWz3Qs= Received: by simark.ca (Postfix, from userid 112) id 3FA351E098; Thu, 23 Oct 2025 14:32:21 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=simark.ca header.i=@simark.ca header.a=rsa-sha256 header.s=mail header.b=o5dsu4OU; dkim-atps=neutral Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 9ACAD1E098 for ; Thu, 23 Oct 2025 14:32:20 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 34DD03858019 for ; Thu, 23 Oct 2025 18:32:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 34DD03858019 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=simark.ca header.i=@simark.ca header.a=rsa-sha256 header.s=mail header.b=o5dsu4OU Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id DDE18385841D for ; Thu, 23 Oct 2025 18:31:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DDE18385841D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark.ca ARC-Filter: OpenARC Filter v1.0.0 sourceware.org DDE18385841D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=158.69.221.121 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1761244306; cv=none; b=pPEq24bR4IwBZ+QoGM8LofPpVxDoAaPNpRH3IQCv8mKDE2Zglof2od7rXNq06lmyEJB+LlDg8QszQKhOq3z2nfGebCqOpy5qEwRHBXcINue8zOXwAsxNLZ8/tiXCqMHqisSaQm2HJJwkkrsCI7ER5avw2JJfIw1NX05GwxwXUdQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1761244306; c=relaxed/simple; bh=x0h4RaXr8IgrMoM8GWqvNBaRWuvskaC6MawieVI+d9Y=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=BzsEH3Sc8kmleUqMXN0+Mui75gjQT8H2QQXxQP6rPkhE0sObc2mP6cvN64YzCEthIT9AaLbQT+eJE1VTJOwH7KctHW/PMg71j2ObzvW0l/i9AcgYu1j3xFii5Tr2bpxZTiVCJwxxWoNfVe9WyYCCLJcHnuwbl1qnmu+H1ZeQfGI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DDE18385841D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simark.ca; s=mail; t=1761244306; bh=x0h4RaXr8IgrMoM8GWqvNBaRWuvskaC6MawieVI+d9Y=; h=Date:Subject:To:References:From:In-Reply-To:From; b=o5dsu4OUcKm8AyNpFmCwQwqWTv1gXcbhxvwP70uBwMOwO3Xb8qKX+Yi5iIFqG5Hvu jiFP8XW3MYq7/l/HGuHSBBm8eMAtoZQtU5UsxeaqzMMX+Oh6InGXnGdeH98i2fzi0J 9zeC/sReINT+U8TaALF8xR0rdXAIvrY8+IYWb5yI= Received: by simark.ca (Postfix) id 63F2A1E04C; Thu, 23 Oct 2025 14:31:46 -0400 (EDT) Message-ID: Date: Thu, 23 Oct 2025 14:31:45 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 2/2] Free multidicts from blockvector To: Tom Tromey , gdb-patches@sourceware.org References: <20251023-mdict-free-v1-0-ad02b2bdd549@tromey.com> <20251023-mdict-free-v1-2-ad02b2bdd549@tromey.com> Content-Language: fr From: Simon Marchi In-Reply-To: <20251023-mdict-free-v1-2-ad02b2bdd549@tromey.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org On 10/23/25 1:17 PM, Tom Tromey wrote: > Currently, nothing in the tree ever calls mdict_free. However, code > does heap-allocate some multidicts. A simple way to see this is to > use valgrind, run "gdb -readnow" on the executable created by > gdb.dwarf2/struct-with-sig.exp, and then use "file" to clear the > objfile list. This yields: > > ==1522843== 144 (16 direct, 128 indirect) bytes in 1 blocks are definitely lost in loss record 905 of 3,005 > ==1522843== at 0x4843866: malloc (vg_replace_malloc.c:446) > ==1522843== by 0x48E397: xmalloc (alloc.c:52) > ==1522843== by 0x59DE66: multidictionary* xnew() (poison.h:102) > ==1522843== by 0x59CFF4: mdict_create_hashed_expandable(language) (dictionary.c:965) > ==1522843== by 0x50A269: buildsym_compunit::finish_block_internal(symbol*, pending**, pending_block*, dynamic_prop const*, unsigned long, unsigned long, int, int) (buildsym.c:221) > ==1522843== by 0x50AE04: buildsym_compunit::end_compunit_symtab_get_static_block(unsigned long, int, int) (buildsym.c:818) > ==1522843== by 0x50C4CF: buildsym_compunit::end_expandable_symtab(unsigned long) (buildsym.c:1037) > ==1522843== by 0x61DBC6: process_full_type_unit (read.c:4970) > > This patch fixes the leaks by calling mdict_free when a blockvector is > destroyed. > --- > gdb/block.c | 6 ++++++ > gdb/block.h | 2 ++ > 2 files changed, 8 insertions(+) > > diff --git a/gdb/block.c b/gdb/block.c > index 02e6d0e4be2bab2c1b3750a2f396e4bc97b7bc5d..2d8d40ec4eb94a1c891a3f8b48972eff3050e66d 100644 > --- a/gdb/block.c > +++ b/gdb/block.c > @@ -842,6 +842,12 @@ blockvector::append_block (struct block *block) > m_blocks.push_back (block); > } > > +blockvector::~blockvector () > +{ > + for (struct block *bl : m_blocks) > + mdict_free (bl->multidict ()); > +} Ideally it would be struct block's just to call that. You could add a destructor to struct block and call it explicitly here. It would be the same result, but would be more correct encapsulation-wise. But I guess this is fine too for the time being. > + > /* Implement 'maint info blocks' command. If passed an argument then > print a list of all blocks at the given address. With no arguments > then list all blocks at the current address of the current inferior. */ > diff --git a/gdb/block.h b/gdb/block.h > index 61070619ca7daa7b3310a9c5cd8d6ca86c044ada..98ce5a3839dbb8419c9e3a918d27b3b58485fea4 100644 > --- a/gdb/block.h > +++ b/gdb/block.h > @@ -424,6 +424,8 @@ struct blockvector > : m_blocks (nblocks, nullptr) > {} > > + ~blockvector (); Since there is a user-defined destructor, I would add a DISABLE_COPY_AND_ASSIGN. Otherwise, LGTM. Approved-By: Simon Marchi Simon