From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id GkidHAHMFWqowx0AWB0awg (envelope-from ) for ; Tue, 26 May 2026 12:36:17 -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=wUfSRQQH; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 617E91E0A3; Tue, 26 May 2026 12:36:17 -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 vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (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 601641E024 for ; Tue, 26 May 2026 12:36:16 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C4AD04BA7990 for ; Tue, 26 May 2026 16:36:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C4AD04BA7990 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=wUfSRQQH Received: from omta38.uswest2.a.cloudfilter.net (omta38.uswest2.a.cloudfilter.net [35.89.44.37]) by sourceware.org (Postfix) with ESMTPS id B6EF44BA2E19 for ; Tue, 26 May 2026 16:35:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B6EF44BA2E19 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 B6EF44BA2E19 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=35.89.44.37 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1779813334; cv=none; b=QN04ovlsL3k0FHqUQ5pT8kzbZswCu9b5Qx7lWRdJ2mRNjalbeKb1UL8mAeL3QxjpAxCzPsOA2/jSNr9Ttn1QApcfwUmZ6k1h9jd6331awHzQkfSnn82+YjztWPiQSUcul7RU9Nh8bes3MS5kR5ydhB9zx83gOtrbcbb27bF8M9s= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1779813334; c=relaxed/simple; bh=Wd0kLWfklAB4B43TTp5Lxd0EkW+Z8GH41szEZAbWZ5g=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=QV1MuxnQkl5GJrdDWgEySVWrn1n9NcH1ArpbRyflPVpCOWTnYK1YNDByE22MEclxHfBcycKVq7Lk1ZwZ3DAa8wcvRHKyVtt3Zv8DVNG5LfGX06FI2+/6w4yu3lClJJ5heufSKCTwgulC1drywuYX7BIAUWeq/1/LHvbi0RLCfC4= ARC-Authentication-Results: i=1; sourceware.org; dkim=policy (768-bit key, unprotected) header.d=tromey.com header.i=@tromey.com header.a=rsa-sha256 header.s=default header.b=wUfSRQQH reason="signing key too small" DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B6EF44BA2E19 Received: from eig-obgw-5005b.ext.cloudfilter.net ([10.0.29.189]) by cmsmtp with ESMTPS id RrO7wuAeoMFEgRukewXT5P; Tue, 26 May 2026 16:35:32 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id RukdwaiC5DvkeRukewvTDl; Tue, 26 May 2026 16:35:32 +0000 X-Authority-Analysis: v=2.4 cv=RaOQC0tv c=1 sm=1 tr=0 ts=6a15cbd4 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=NGcC8JguVDcA:10 a=ItBw4LHWJt0A:10 a=7CQSdrXTAAAA:8 a=T1SIf9GYsVDyLl81_DkA:9 a=a-qgeE7W1pNrGK8U0ZQC:22 a=DCx65vhANUyCzuf5D8fC:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Type:MIME-Version:Message-ID:Date:References:In-Reply-To :Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding: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=UFF8NPxO5uWUFOV0EvofTsE+dS82MUJ0XSjiu/GZU/k=; b=wUfSRQQHlDy3qo7WuvKiURPvmk FS9Nnn+ZmPPPkwvrSQZDU2djDaOHC5tqwIu6nb+HyGJtmiy3/CUAJ0JmujI6Wy240gXMDE6r19HbL 6ulw5mIr0TbKrL/GA6RU1K3vR; Received: from 75-166-225-82.hlrn.qwest.net ([75.166.225.82]:36128 helo=bapiya) by box5379.bluehost.com with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.99.2) (envelope-from ) id 1wRukd-00000001eRG-1t6m; Tue, 26 May 2026 10:35:31 -0600 From: Tom Tromey To: Matthieu Longo Cc: , Tom Tromey , Andrew Burgess Subject: Re: [PATCH v1] gdb/python: fix memory leak in gdb_py_tp_name In-Reply-To: <20260526160459.270322-1-matthieu.longo@arm.com> (Matthieu Longo's message of "Tue, 26 May 2026 17:04:59 +0100") References: <20260526160459.270322-1-matthieu.longo@arm.com> X-Attribution: Tom Date: Tue, 26 May 2026 10:35:30 -0600 Message-ID: <87fr3e6sdp.fsf@tromey.com> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain 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: 75.166.225.82 X-Source-L: No X-Exim-ID: 1wRukd-00000001eRG-1t6m X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 75-166-225-82.hlrn.qwest.net (bapiya) [75.166.225.82]:36128 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: MS4xfJb1MgEqsuyWlWUIgzkXsDwheYE7L/35ZYfWuxYVBzaGDxYFYfH77nztELjMMt5l2lbK1I/hFEDqwZCNYGUZ7RqhmmQSRtcJXo4ELIOVSeoov8mngjZZ ptGWKBChjD068IUKP3BXkgIGHxSwm6MolkvDzxkSO32qersmYNB064yxdWbS2ripwgLztES+WlRgi3Mg5068jA73Xtt5ZavClqA= 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 >>>>> "Matthieu" == Matthieu Longo writes: Matthieu> The proposed approach consists in changing gdb_py_tp_name() to return a Matthieu> std::string That seems fine. Matthieu> A unfortunate side effect of this fix is that every call sites where the Matthieu> tp_name is printed, must now use `.c_str()' because PyErr_Format() Matthieu> and its siblings cannot handle std::string. Yeah, that's unfortunate but normal. Matthieu> /* Return the type's fully qualified name from a PyTypeObject. */ Matthieu> -const char * Matthieu> +std::string Matthieu> gdb_py_tp_name (PyTypeObject *py_type) noexcept Matthieu> { Matthieu> #if PY_VERSION_HEX >= 0x030d0000 Matthieu> /* Note: PyType_GetFullyQualifiedName() was added in version 3.13, and is Matthieu> part of the stable ABI since version 3.13. */ Matthieu> - PyObject *fully_qualified_name = PyType_GetFullyQualifiedName (py_type); Matthieu> + gdbpy_ref<> fully_qualified_name (PyType_GetFullyQualifiedName (py_type)); Matthieu> if (fully_qualified_name == nullptr) Matthieu> return nullptr; First, returning nullptr here seems really weird. I think this should cause a crash? In C++23 this constructor is even deleted. Second, if PyType_GetFullyQualifiedName fails, this will violate the invariants gdb normally uses for error handling. Matthieu> - return PyUnicode_AsUTF8AndSize (fully_qualified_name, nullptr); Matthieu> + return PyUnicode_AsUTF8AndSize (fully_qualified_name.get (), nullptr); I think this can also fail. Matthieu> + gdbpy_ref<> qualname (PyType_GetQualName (py_type)); Matthieu> if (qualname == nullptr) Matthieu> return nullptr; Matthieu> - return PyUnicode_AsUTF8AndSize (qualname, nullptr); Matthieu> + return PyUnicode_AsUTF8AndSize (qualname.get (), nullptr); Similar stuff in these spots. Tom