summaryrefslogtreecommitdiff
path: root/sha1-file.c
diff options
context:
space:
mode:
authorRené Scharfe <l.s.r@web.de>2019-01-07 16:48:02 (GMT)
committerJunio C Hamano <gitster@pobox.com>2019-01-07 16:57:18 (GMT)
commit6881925ef5a0a8b1a33e2f4ceec2ce7ad007dc7a (patch)
treef5a475836ac2e266d7e9fdb7c69bb203511739b7 /sha1-file.c
parent0d0ac3826a3bbb9247e39e12623bbcfdd722f24c (diff)
downloadgit-6881925ef5a0a8b1a33e2f4ceec2ce7ad007dc7a.zip
git-6881925ef5a0a8b1a33e2f4ceec2ce7ad007dc7a.tar.gz
git-6881925ef5a0a8b1a33e2f4ceec2ce7ad007dc7a.tar.bz2
sha1-file: close fd of empty file in map_sha1_file_1()
map_sha1_file_1() checks if the file it is about to mmap() is empty and errors out in that case and explains the situation in an error message. It leaks the private handle to that empty file, though. Have the function clean up after itself and close the file descriptor before exiting early. Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'sha1-file.c')
-rw-r--r--sha1-file.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/sha1-file.c b/sha1-file.c
index 5bd11c8..fb098c7 100644
--- a/sha1-file.c
+++ b/sha1-file.c
@@ -971,6 +971,7 @@ static void *map_sha1_file_1(struct repository *r, const char *path,
if (!*size) {
/* mmap() is forbidden on empty files */
error(_("object file %s is empty"), path);
+ close(fd);
return NULL;
}
map = xmmap(NULL, *size, PROT_READ, MAP_PRIVATE, fd, 0);