From 6881925ef5a0a8b1a33e2f4ceec2ce7ad007dc7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Mon, 7 Jan 2019 17:48:02 +0100 Subject: [PATCH] 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 Signed-off-by: Junio C Hamano --- sha1-file.c | 1 + 1 file changed, 1 insertion(+) diff --git a/sha1-file.c b/sha1-file.c index 5bd11c85bc..fb098c7a17 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);