diff mbox

[5/5] Fix file descriptor leakage in maps_init

Message ID 1299084010-8762-6-git-send-email-ken.werner@linaro.org
State Accepted
Commit 6a072982ddd0b8c1597ac2aa17559732c8b5e763
Headers show

Commit Message

Ken Werner March 2, 2011, 4:40 p.m. UTC
From: Zachary T Welch <zwelch@codesourcery.com>

If mmap fails, be sure to close the maps file before returning an error.

Signed-off-by: Zachary T Welch <zwelch@codesourcery.com>
Signed-off-by: Ken Werner <ken.werner@linaro.org>
---
 src/os-linux.h |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)
diff mbox

Patch

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;