Skip to content

Commit 6881925

Browse files
rscharfegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0d0ac38 commit 6881925

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

sha1-file.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -971,6 +971,7 @@ static void *map_sha1_file_1(struct repository *r, const char *path,
971971
if (!*size) {
972972
/* mmap() is forbidden on empty files */
973973
error(_("object file %s is empty"), path);
974+
close(fd);
974975
return NULL;
975976
}
976977
map = xmmap(NULL, *size, PROT_READ, MAP_PRIVATE, fd, 0);

0 commit comments

Comments
 (0)