aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2016-06-19 23:04:07 -0400
committerMike Frysinger <vapier@gentoo.org>2016-06-19 23:04:07 -0400
commit548c5db10349d6a5ee3d8dbe1da14e55655ca530 (patch)
tree9731198a38b14ef5fde6b66ec775b8ecbfe9dca5
parentpaxmacho: simplify readmacho a bit (diff)
downloadpax-utils-548c5db10349d6a5ee3d8dbe1da14e55655ca530.tar.gz
pax-utils-548c5db10349d6a5ee3d8dbe1da14e55655ca530.tar.bz2
pax-utils-548c5db10349d6a5ee3d8dbe1da14e55655ca530.zip
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.
-rw-r--r--paxmacho.c6
1 files changed, 5 insertions, 1 deletions
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)