commit:     548c5db10349d6a5ee3d8dbe1da14e55655ca530
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Mon Jun 20 03:04:07 2016 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> 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)

Reply via email to