Skip to content

Commit 41f1a8e

Browse files
dschogitster
authored andcommitted
pack-mtimes: avoid closing a bogus file descriptor
In 94cd775 (pack-mtimes: support reading .mtimes files, 2022-05-20), code was added to close the file descriptor corresponding to the mtimes file. However, it is possible that opening that file failed, in which case we are closing a file descriptor with the value `-1`. Let's guard that `close()` call. Reported by Coverity. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 652891d commit 41f1a8e

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

pack-mtimes.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ static int load_pack_mtimes_file(char *mtimes_file,
8989
*data_p = data;
9090
}
9191

92-
close(fd);
92+
if (fd >= 0)
93+
close(fd);
9394
return ret;
9495
}
9596

0 commit comments

Comments
 (0)