Skip to content

Commit f9d3b0d

Browse files
authored
Merge pull request libgit2#4201 from pks-t/pks/fileops-fd-leak
fileops: fix leaking fd in `mmap_ro_file`
2 parents d476d02 + 38b6e70 commit f9d3b0d

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/fileops.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,15 +304,19 @@ int git_futils_mmap_ro_file(git_map *out, const char *path)
304304
if (fd < 0)
305305
return fd;
306306

307-
if ((len = git_futils_filesize(fd)) < 0)
308-
return -1;
307+
if ((len = git_futils_filesize(fd)) < 0) {
308+
result = -1;
309+
goto out;
310+
}
309311

310312
if (!git__is_sizet(len)) {
311313
giterr_set(GITERR_OS, "file `%s` too large to mmap", path);
312-
return -1;
314+
result = -1;
315+
goto out;
313316
}
314317

315318
result = git_futils_mmap_ro(out, fd, 0, (size_t)len);
319+
out:
316320
p_close(fd);
317321
return result;
318322
}

0 commit comments

Comments
 (0)