From patchwork Fri Feb 22 21:42:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Baldwin X-Patchwork-Id: 31565 Received: (qmail 104115 invoked by alias); 22 Feb 2019 21:43:18 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 104056 invoked by uid 89); 22 Feb 2019 21:43:17 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx2.freebsd.org Received: from mx2.freebsd.org (HELO mx2.freebsd.org) (8.8.178.116) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 22 Feb 2019 21:43:16 +0000 Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client CN "mx1.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx2.freebsd.org (Postfix) with ESMTPS id 068CD97E62; Fri, 22 Feb 2019 21:43:15 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from smtp.freebsd.org (smtp.freebsd.org [96.47.72.83]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "smtp.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 405D1899A8; Fri, 22 Feb 2019 21:43:14 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from John-Baldwins-MacBook-Pro-3.local (ralph.baldwin.cx [66.234.199.215]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) (Authenticated sender: jhb) by smtp.freebsd.org (Postfix) with ESMTPSA id 5F98617E48; Fri, 22 Feb 2019 21:43:13 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Subject: Re: [RFC] Fix BFD leak in solib-darwin.c From: John Baldwin To: Tom Tromey , gdb-patches@sourceware.org References: <20190222163645.9349-1-tromey@adacore.com> <184aefb1-38fc-cc39-0f3a-4bd350c47e11@FreeBSD.org> Openpgp: preference=signencrypt Message-ID: <71427d4a-6463-0944-146a-1267f08e1947@FreeBSD.org> Date: Fri, 22 Feb 2019 13:42:28 -0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:60.0) Gecko/20100101 Thunderbird/60.5.0 MIME-Version: 1.0 In-Reply-To: <184aefb1-38fc-cc39-0f3a-4bd350c47e11@FreeBSD.org> X-Rspamd-Queue-Id: 405D1899A8 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.97 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-0.99)[-0.993,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.98)[-0.982,0]; ASN(0.00)[asn:11403, ipnet:96.47.64.0/20, country:US] X-IsSubscribed: yes On 2/22/19 9:16 AM, John Baldwin wrote: > On 2/22/19 8:36 AM, Tom Tromey wrote: >> commit 192b62ce0b4bb5c61188f570e127a26d2c32f716 ("Use class to manage >> BFD reference counts") changed darwin_get_dyld_bfd to use: >> >> + dyld_bfd.release (); >> >> rather than >> >> - do_cleanups (cleanup); >> >> However, using release here leaks the BFD. Instead I believe reset >> should be used instead. >> >> I can't readily test this, so please take a look and let me know what >> you think. >> >> gdb/ChangeLog >> 2019-02-22 Tom Tromey >> >> * solib-darwin.c (darwin_get_dyld_bfd): Use reset, not release. >> --- >> gdb/ChangeLog | 4 ++++ >> gdb/solib-darwin.c | 2 +- >> 2 files changed, 5 insertions(+), 1 deletion(-) >> >> diff --git a/gdb/solib-darwin.c b/gdb/solib-darwin.c >> index d3060604bad..da410ad4660 100644 >> --- a/gdb/solib-darwin.c >> +++ b/gdb/solib-darwin.c >> @@ -455,7 +455,7 @@ darwin_get_dyld_bfd () >> if (sub != NULL) >> dyld_bfd = sub; >> else >> - dyld_bfd.release (); >> + dyld_bfd.reset (nullptr); >> } >> return dyld_bfd; >> } > > I haven't tested, but this LGTM. Simon has noticed several instances of > this bug where release() was used instead of reset(). (The most recent one > was in the build-id separate debug file code that I think hasn't been > committed yet.) It might be worth doing a quick sweep of current 'release' > calls (if there aren't too many) to check for other leaks. I did a quick look and this is the only other one I could find that I think is also a leak: diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index 98f46e0416..055cbc8073 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -2722,7 +2722,7 @@ dwarf2_get_dwz_file (struct dwarf2_per_objfile *dwarf2_per_objfile) if (dwz_bfd != NULL) { if (!build_id_verify (dwz_bfd.get (), buildid_len, buildid)) - dwz_bfd.release (); + dwz_bfd.reset (nullptr); } if (dwz_bfd == NULL)