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>
René Scharfe committed
Jan 7, 2019 at 17:48 UTC
6881925ef5a0a8b1a33e2f4ceec2ce7ad007dc7a
1 file changed
+1
sha1-file.c
+1
@@ -971,6 +971,7 @@ static void *map_sha1_file_1(struct repository *r, const char *path,
971
if (!*size) {
972
/* mmap() is forbidden on empty files */
973
error(_("object file %s is empty"), path);
974
+ close(fd);
975
return NULL;
976
}
977
map = xmmap(NULL, *size, PROT_READ, MAP_PRIVATE, fd, 0);