From 66f52fa26b4facbf79e3f74d8bc95f8ac8535c50 Mon Sep 17 00:00:00 2001 From: Taylor Blau Date: Fri, 26 Feb 2021 11:31:02 -0500 Subject: pack-revindex.c: don't close unopened file descriptors When opening a reverse index, load_revindex_from_disk() jumps to the 'cleanup' label in case something goes wrong: the reverse index had the wrong size, an unrecognized version, or similar. It also jumps to this label when the reverse index couldn't be opened in the first place, which will cause an error with the unguarded close() call in the label. Guard this call with "if (fd >= 0)" to make sure that we have a valid file descriptor to close before attempting to close it. Reported-by: Johannes Schindelin Signed-off-by: Taylor Blau Signed-off-by: Junio C Hamano --- pack-revindex.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'pack-revindex.c') diff --git a/pack-revindex.c b/pack-revindex.c index 83fe4de773..4262530449 100644 --- a/pack-revindex.c +++ b/pack-revindex.c @@ -253,7 +253,8 @@ cleanup: *data_p = (const uint32_t *)data; } - close(fd); + if (fd >= 0) + close(fd); return ret; } -- cgit v1.2.3