From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 568741382AC for ; Mon, 20 Jun 2016 03:08:32 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id B91371425A; Mon, 20 Jun 2016 03:08:27 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 848C714232 for ; Mon, 20 Jun 2016 03:08:26 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id B4F64340901 for ; Mon, 20 Jun 2016 03:08:25 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 3DD692423 for ; Mon, 20 Jun 2016 03:08:22 +0000 (UTC) From: "Mike Frysinger" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Mike Frysinger" Message-ID: <1466391847.548c5db10349d6a5ee3d8dbe1da14e55655ca530.vapier@gentoo> Subject: [gentoo-commits] proj/pax-utils:master commit in: / X-VCS-Repository: proj/pax-utils X-VCS-Files: paxmacho.c X-VCS-Directories: / X-VCS-Committer: vapier X-VCS-Committer-Name: Mike Frysinger X-VCS-Revision: 548c5db10349d6a5ee3d8dbe1da14e55655ca530 X-VCS-Branch: master Date: Mon, 20 Jun 2016 03:08:22 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 4dae736a-31f5-4557-9146-426567983505 X-Archives-Hash: ca4a77989e0a8aed0d12b5d542c0f330 commit: 548c5db10349d6a5ee3d8dbe1da14e55655ca530 Author: Mike Frysinger gentoo org> AuthorDate: Mon Jun 20 03:04:07 2016 +0000 Commit: Mike Frysinger gentoo org> CommitDate: Mon Jun 20 03:04:07 2016 +0000 URL: https://gitweb.gentoo.org/proj/pax-utils.git/commit/?id=548c5db1 paxmacho: fix readmacho fd leakage on error If the readmacho_fd helper returns an error for any reason, we don't close the fd. Add logic to handle that scenario. paxmacho.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/paxmacho.c b/paxmacho.c index 142af6e..638453a 100644 --- a/paxmacho.c +++ b/paxmacho.c @@ -190,11 +190,15 @@ inline static uint32_t read_mach_header(fatobj *fobj, void *addr) fatobj *readmacho(const char *filename) { int fd; + fatobj *ret; if ((fd = open(filename, O_RDONLY)) == -1) return NULL; - return readmacho_fd(filename, fd, 0); + ret = readmacho_fd(filename, fd, 0); + if (ret == NULL) + close(fd); + return ret; } fatobj *readmacho_fd(const char *filename, int fd, size_t len)