1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-05-12 12:56:08 +02:00

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 <Johannes.Schindelin@gmx.de>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Taylor Blau 2021-02-26 11:31:02 -05:00 committed by Junio C Hamano
parent 6885cd7dc5
commit 66f52fa26b

View File

@ -253,7 +253,8 @@ static int load_revindex_from_disk(char *revindex_name,
*data_p = (const uint32_t *)data;
}
close(fd);
if (fd >= 0)
close(fd);
return ret;
}