From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 6ZtpDc9j+mgFxAQAWB0awg (envelope-from ) for ; Thu, 23 Oct 2025 13:20:15 -0400 Authentication-Results: simark.ca; dkim=fail reason="signature verification failed" (768-bit key; unprotected) header.d=tromey.com header.i=@tromey.com header.a=rsa-sha256 header.s=default header.b=TU3lisyH; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 32A131E04C; Thu, 23 Oct 2025 13:20:15 -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.1 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_INVALID,DKIM_SIGNED,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 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 BACBE1E04C for ; Thu, 23 Oct 2025 13:20:14 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 068B93858424 for ; Thu, 23 Oct 2025 17:20:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 068B93858424 Authentication-Results: sourceware.org; dkim=fail reason="signature verification failed" (768-bit key, unprotected) header.d=tromey.com header.i=@tromey.com header.a=rsa-sha256 header.s=default header.b=TU3lisyH Received: from omta40.uswest2.a.cloudfilter.net (omta40.uswest2.a.cloudfilter.net [35.89.44.39]) by sourceware.org (Postfix) with ESMTPS id 6E9D7385841D for ; Thu, 23 Oct 2025 17:18:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6E9D7385841D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6E9D7385841D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=35.89.44.39 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1761239894; cv=none; b=V1cCVq6ey+oxTW4szzCKgFdAD1z/v27vmr9LG7FPUZX51YCGLO2Abdpy5wIxoHuSUgzQgDCnCyOEp0zbeW+UpGuH9XhXMgh22qsZaiBJ+qRQbvy4zzICkFVSTVmndfFfOCq7WA23nUVep4jYPtq6c0mTRT7XGGsItWkD+QffMN4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1761239894; c=relaxed/simple; bh=dJ8aQRwDr32KWmQj/n5tez/SpdXSwfbkS0SAfDdCyNQ=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=IS7obE/RYI963FaI4ErY15BZ2OIS9CXwtPK46bKltwP2N18IWqFD1IhGi/AAEFoTTUoKTrc8weNtCp9IVU149LDsYejL5O5v8N4KowxZplgJ7o/DZXeKAcjU60CmE0XVqLisZBtibBFGRpQ8oRkS4S12mqxdbuV164z3Pqd+/BE= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6E9D7385841D Received: from eig-obgw-5003b.ext.cloudfilter.net ([10.0.29.155]) by cmsmtp with ESMTPS id BZzVvdbc7aPqLByx3vKwQ4; Thu, 23 Oct 2025 17:18:13 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id BywRvzxe2uWNOBywRvaD5M; Thu, 23 Oct 2025 17:17:35 +0000 X-Authority-Analysis: v=2.4 cv=N+gpF39B c=1 sm=1 tr=0 ts=68fa6355 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=IkcTkHD0fZMA:10 a=x6icFKpwvdMA:10 a=ItBw4LHWJt0A:10 a=rQqKJDYPa1zVIuVqnOIA:9 a=QEXdDO2ut3YA:10 a=VS4QxaUSPT0UtbFnIvSC:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To: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=Qa0EP7UgvdKH9T6LqY3a1quc3s/E95y+Y06UB5qALmw=; b=TU3lisyHP2X0TZ0RASSaNYwWMD 5dsfflwtrByLjB8aFFxRgLooys+Jo8Qxl5++3X4iMJLXaR4+10klNXr9OwU9/FDRvGLLYNy4sBlNX 7eCt2kSkpiPT/rNROLthwCHYb; Received: from 97-122-110-68.hlrn.qwest.net ([97.122.110.68]:33134 helo=[192.168.0.17]) by box5379.bluehost.com with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1vBywR-00000002lTI-0rrq; Thu, 23 Oct 2025 11:17:35 -0600 From: Tom Tromey Date: Thu, 23 Oct 2025 11:17:33 -0600 Subject: [PATCH 1/2] Two bug fixes in mdict_free MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20251023-mdict-free-v1-1-ad02b2bdd549@tromey.com> References: <20251023-mdict-free-v1-0-ad02b2bdd549@tromey.com> In-Reply-To: <20251023-mdict-free-v1-0-ad02b2bdd549@tromey.com> To: gdb-patches@sourceware.org Cc: Tom Tromey X-Mailer: b4 0.14.2 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.110.68 X-Source-L: No X-Exim-ID: 1vBywR-00000002lTI-0rrq X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-110-68.hlrn.qwest.net ([192.168.0.17]) [97.122.110.68]:33134 X-Source-Auth: tom+tromey.com X-Email-Count: 2 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfJewwWXsz3Cdj0ZCqMajovz5F+GXKij50U56SM+wCVAiFH2ZvIt19GBszso5Ah/9wnNm4BxPzJD57l4HidHSBQADjc63+HyL++Jn51/X4d4hxLwPK3nu /iM87T9oQma9DyblNCS/COaUMUJ9Dp3sohXjsOIx5Q7+St7iuCKiRV4Qnb0YKeN1WNkKv6ub1Tf9drN7rwdzq13rz6QtavcmzfE= 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 A heap-allocated multidictionary should be freed by calling mdict_free. However, while this function does free the contents of the dictionary, it neglects to free the dictionary itself. There's also a second bug, which is that if a multidictionary is created with no dictionaries, gdb will crash on the first line of mdict_free: enum dict_type type = mdict->dictionaries[0]->vector->type; So, this patch also adds the type to struct multidictionary, avoiding this problem. Note that this does not increase the structure size on x86-64, because the new member fits into the padding. --- gdb/dictionary.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/gdb/dictionary.c b/gdb/dictionary.c index f435ad5a47e817dc59087ac2ff5637415a9256d6..9dec7ccb2af5fad1e0cb62b92dc79e41e2fbbc15 100644 --- a/gdb/dictionary.c +++ b/gdb/dictionary.c @@ -911,6 +911,9 @@ struct multidictionary /* The number of language dictionaries currently allocated. Only used for expandable dictionaries. */ unsigned short n_allocated_dictionaries; + + /* The type of dictionary. */ + enum dict_type type; }; /* A helper function to collate symbols on the pending list by language. */ @@ -948,6 +951,7 @@ mdict_create_hashed (struct obstack *obstack, retval->dictionaries = XOBNEWVEC (obstack, struct dictionary *, nsyms.size ()); retval->n_allocated_dictionaries = nsyms.size (); + retval->type = DICT_HASHED; int idx = 0; for (const auto &[language, symlist] : nsyms) @@ -969,6 +973,7 @@ mdict_create_hashed_expandable (enum language language) retval->n_allocated_dictionaries = 1; retval->dictionaries = XNEW (struct dictionary *); retval->dictionaries[0] = dict_create_hashed_expandable (language); + retval->type = DICT_HASHED_EXPANDABLE; return retval; } @@ -988,6 +993,7 @@ mdict_create_linear (struct obstack *obstack, retval->dictionaries = XOBNEWVEC (obstack, struct dictionary *, nsyms.size ()); retval->n_allocated_dictionaries = nsyms.size (); + retval->type = DICT_LINEAR; int idx = 0; for (const auto &[language, symlist] : nsyms) @@ -1009,6 +1015,7 @@ mdict_create_linear_expandable (enum language language) retval->n_allocated_dictionaries = 1; retval->dictionaries = XNEW (struct dictionary *); retval->dictionaries[0] = dict_create_linear_expandable (language); + retval->type = DICT_LINEAR_EXPANDABLE; return retval; } @@ -1018,15 +1025,12 @@ mdict_create_linear_expandable (enum language language) void mdict_free (struct multidictionary *mdict) { - /* Grab the type of dictionary being used. */ - enum dict_type type = mdict->dictionaries[0]->vector->type; - /* Loop over all dictionaries and free them. */ for (unsigned short idx = 0; idx < mdict->n_allocated_dictionaries; ++idx) dict_free (mdict->dictionaries[idx]); /* Free the dictionary list, if needed. */ - switch (type) + switch (mdict->type) { case DICT_HASHED: case DICT_LINEAR: @@ -1036,6 +1040,7 @@ mdict_free (struct multidictionary *mdict) case DICT_HASHED_EXPANDABLE: case DICT_LINEAR_EXPANDABLE: xfree (mdict->dictionaries); + xfree (mdict); break; } } -- 2.49.0