Message ID | 20250125013258.2694909-1-amerey@redhat.com |
---|---|
State | Committed |
Delegated to: | Mark Wielaard |
Headers |
Return-Path: <elfutils-devel-bounces~patchwork=sourceware.org@sourceware.org> 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 6D1C83858C48 for <patchwork@sourceware.org>; Sat, 25 Jan 2025 01:33:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6D1C83858C48 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=EJPs4Dpj X-Original-To: elfutils-devel@sourceware.org Delivered-To: elfutils-devel@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 7EBB83858D1E for <elfutils-devel@sourceware.org>; Sat, 25 Jan 2025 01:33:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7EBB83858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 7EBB83858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1737768784; cv=none; b=hiXvHkY4Gi33TXAd8nwh2zfdKKmAmuPIPP5qsRsMh8O0Q/otl5Jg0UIy4VcyT8Or+Ki89ojr7BV3wu49X3BWiWdoS5D/l2oNnBoiOPkf3pGbQAZBtT9gUgj/Br57cLsLXY0c8vrPadwkHY3Noq5QdbkoZcoG1vmqQlyk2hyvqFI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1737768784; c=relaxed/simple; bh=PeGZaqo8eH1HG8WiHYJ77vWJr/iNAv7SCYgW/tBEuIM=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=gELyTqxz7a2wcwzDetKz9IOVBSQhPfE4vA89W0u5zwHn0XRfEGR883DVizpYFMRCK5iBEhVX5SJ1DRRGc07TYNA0KtNCiVixe0P26b6xP6GPYohbV4WldStat6mIIe/kKE3eFZh5qr7KxwapTHtU2SKiHiz9TuAoIsVDP3xIJjw= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7EBB83858D1E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737768784; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Dp58LI2LkLel/BHtgicvtIZaDomr0bkQypkSzavsVuE=; b=EJPs4DpjA6rOvGGz47MdfKNRtDF+Ed8jsFDA629U6Tjgjg6x0OuNyMv8YiBPypaEQiF8b+ DFyncZncKC1o+m5MJKUN73nXxvrgEBgge4XBzTqyIhOlPBCGTb56ujSXlt6bEW3vteAVB2 nSDRIkzSMOKUw47JD7iwmj2svnFf5+Y= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-625-96AlhYXGPmeDWw4JPLytCQ-1; Fri, 24 Jan 2025 20:33:02 -0500 X-MC-Unique: 96AlhYXGPmeDWw4JPLytCQ-1 X-Mimecast-MFC-AGG-ID: 96AlhYXGPmeDWw4JPLytCQ Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 3FD7719560B2 for <elfutils-devel@sourceware.org>; Sat, 25 Jan 2025 01:33:01 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.90.6]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 6712D19560A7; Sat, 25 Jan 2025 01:33:00 +0000 (UTC) From: Aaron Merey <amerey@redhat.com> To: elfutils-devel@sourceware.org Cc: Aaron Merey <amerey@redhat.com> Subject: [PATCH] src/readelf.c: Close skel_fd Date: Fri, 24 Jan 2025 20:32:58 -0500 Message-ID: <20250125013258.2694909-1-amerey@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: a2n9GMU2BP_AWJw_0fk8OJmE5yo7u898oPbWV0AaZxE_1737768781 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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: elfutils-devel@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Elfutils-devel mailing list <elfutils-devel.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/elfutils-devel>, <mailto:elfutils-devel-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/elfutils-devel/> List-Post: <mailto:elfutils-devel@sourceware.org> List-Help: <mailto:elfutils-devel-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/elfutils-devel>, <mailto:elfutils-devel-request@sourceware.org?subject=subscribe> Errors-To: elfutils-devel-bounces~patchwork=sourceware.org@sourceware.org |
Series |
src/readelf.c: Close skel_fd
|
|
Commit Message
Aaron Merey
Jan. 25, 2025, 1:32 a.m. UTC
skel_fd is passed to create_dwfl, which calls dup() on skel_fd.
create_dwfl handles closing the dup'ed fd but not the original.
Ensure the original skel_fd is closed after it's passed to create_dwfl.
Signed-off-by: Aaron Merey <amerey@redhat.com>
---
src/readelf.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
Comments
Hi Aaron, On Fri, Jan 24, 2025 at 08:32:58PM -0500, Aaron Merey wrote: > skel_fd is passed to create_dwfl, which calls dup() on skel_fd. > create_dwfl handles closing the dup'ed fd but not the original. > > Ensure the original skel_fd is closed after it's passed to create_dwfl. Nice find. We should add --track-fds=yes to our valgrind testing. It would have found this earlier. Two of our tests currently fail with: -==75005== Open file descriptor 5: testfile-splitdwarf-4 -==75005== at 0x4A1E023: open (in /usr/lib64/libc.so.6) -==75005== by 0x41392B: open (fcntl2.h:55) -==75005== by 0x41392B: print_debug (readelf.c:11919) -==75005== by 0x416451: process_elf_file (readelf.c:1084) -==75005== by 0x4170CC: process_dwflmod (readelf.c:840) -==75005== by 0x489CAE0: dwfl_getmodules (dwfl_getmodules.c:86) -==75005== by 0x406964: process_file (readelf.c:948) -==75005== by 0x401D11: main (readelf.c:417) This file descriptor leak disappears with your patch. Thanks, Mark > Signed-off-by: Aaron Merey <amerey@redhat.com> > --- > src/readelf.c | 8 +++++++- > 1 file changed, 7 insertions(+), 1 deletion(-) > > diff --git a/src/readelf.c b/src/readelf.c > index 3e97b64c..6526db07 100644 > --- a/src/readelf.c > +++ b/src/readelf.c > @@ -11921,7 +11921,13 @@ print_debug (Dwfl_Module *dwflmod, Ebl *ebl, GElf_Ehdr *ehdr) > fprintf (stderr, "Warning: Couldn't open DWARF skeleton file" > " '%s'\n", skel_name); > else > - skel_dwfl = create_dwfl (skel_fd, skel_name); > + { > + skel_dwfl = create_dwfl (skel_fd, skel_name); > + > + /* skel_fd was dup'ed by create_dwfl. We can close the > + original now. */ > + close (skel_fd); > + } > > if (skel_dwfl != NULL) > { > -- > 2.47.1 >
diff --git a/src/readelf.c b/src/readelf.c index 3e97b64c..6526db07 100644 --- a/src/readelf.c +++ b/src/readelf.c @@ -11921,7 +11921,13 @@ print_debug (Dwfl_Module *dwflmod, Ebl *ebl, GElf_Ehdr *ehdr) fprintf (stderr, "Warning: Couldn't open DWARF skeleton file" " '%s'\n", skel_name); else - skel_dwfl = create_dwfl (skel_fd, skel_name); + { + skel_dwfl = create_dwfl (skel_fd, skel_name); + + /* skel_fd was dup'ed by create_dwfl. We can close the + original now. */ + close (skel_fd); + } if (skel_dwfl != NULL) {