From patchwork Wed Mar 2 16:40:10 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Werner X-Patchwork-Id: 285 Return-Path: Delivered-To: unknown Received: from imap.gmail.com (74.125.159.109) by localhost6.localdomain6 with IMAP4-SSL; 08 Jun 2011 14:41:27 -0000 Delivered-To: patches@linaro.org Received: by 10.224.19.208 with SMTP id c16cs193815qab; Wed, 2 Mar 2011 08:40:15 -0800 (PST) Received: by 10.227.12.6 with SMTP id v6mr5748251wbv.44.1299084014666; Wed, 02 Mar 2011 08:40:14 -0800 (PST) Received: from mtagate5.uk.ibm.com (mtagate5.uk.ibm.com [194.196.100.165]) by mx.google.com with ESMTPS id h47si287438wer.76.2011.03.02.08.40.13 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 02 Mar 2011 08:40:13 -0800 (PST) Received-SPF: neutral (google.com: 194.196.100.165 is neither permitted nor denied by best guess record for domain of ken.werner@linaro.org) client-ip=194.196.100.165; Authentication-Results: mx.google.com; spf=neutral (google.com: 194.196.100.165 is neither permitted nor denied by best guess record for domain of ken.werner@linaro.org) smtp.mail=ken.werner@linaro.org Received: from d06nrmr1307.portsmouth.uk.ibm.com (d06nrmr1307.portsmouth.uk.ibm.com [9.149.38.129]) by mtagate5.uk.ibm.com (8.13.1/8.13.1) with ESMTP id p22GeCDe009460 for ; Wed, 2 Mar 2011 16:40:12 GMT Received: from d06av01.portsmouth.uk.ibm.com (d06av01.portsmouth.uk.ibm.com [9.149.37.212]) by d06nrmr1307.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p22GeOxH1499364 for ; Wed, 2 Mar 2011 16:40:24 GMT Received: from d06av01.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av01.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p22GeCFf000383 for ; Wed, 2 Mar 2011 09:40:12 -0700 Received: from localhost.localdomain (dyn-9-152-224-51.boeblingen.de.ibm.com [9.152.224.51]) by d06av01.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id p22GeA0O000307; Wed, 2 Mar 2011 09:40:12 -0700 From: Ken Werner To: libunwind-devel@nongnu.org Subject: [PATCH 5/5] Fix file descriptor leakage in maps_init Date: Wed, 2 Mar 2011 17:40:10 +0100 Message-Id: <1299084010-8762-6-git-send-email-ken.werner@linaro.org> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1299084010-8762-1-git-send-email-ken.werner@linaro.org> References: <1299084010-8762-1-git-send-email-ken.werner@linaro.org> From: Zachary T Welch If mmap fails, be sure to close the maps file before returning an error. Signed-off-by: Zachary T Welch Signed-off-by: Ken Werner --- src/os-linux.h | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-) diff --git a/src/os-linux.h b/src/os-linux.h index af301ce..4e225dc 100644 --- a/src/os-linux.h +++ b/src/os-linux.h @@ -80,7 +80,11 @@ maps_init (struct map_iterator *mi, pid_t pid) cp = mmap (0, mi->buf_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (cp == MAP_FAILED) - return -1; + { + close(mi->fd); + mi->fd = -1; + return -1; + } else { mi->offset = 0;