diff options
author | Edward Thomson <ethomson@edwardthomson.com> | 2017-04-12 09:21:26 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-12 09:21:26 +0100 |
commit | f9d3b0d05f19a59e3327deabc2edc93e507c6aa3 (patch) | |
tree | a70c1b5ca1ba508cf5ae7d28a4b8fe92cbb26ecd | |
parent | d476d024d0415a566b858daec7faa961587bae14 (diff) | |
parent | 38b6e700272b387aaa959a5d362467e8bcd836b4 (diff) | |
download | libgit2-f9d3b0d05f19a59e3327deabc2edc93e507c6aa3.tar.gz |
Merge pull request #4201 from pks-t/pks/fileops-fd-leak
fileops: fix leaking fd in `mmap_ro_file`
-rw-r--r-- | src/fileops.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/fileops.c b/src/fileops.c index f9552a5f8..a0a2795c6 100644 --- a/src/fileops.c +++ b/src/fileops.c @@ -304,15 +304,19 @@ int git_futils_mmap_ro_file(git_map *out, const char *path) if (fd < 0) return fd; - if ((len = git_futils_filesize(fd)) < 0) - return -1; + if ((len = git_futils_filesize(fd)) < 0) { + result = -1; + goto out; + } if (!git__is_sizet(len)) { giterr_set(GITERR_OS, "file `%s` too large to mmap", path); - return -1; + result = -1; + goto out; } result = git_futils_mmap_ro(out, fd, 0, (size_t)len); +out: p_close(fd); return result; } |