Skip to content

Commit 66f52fa

Browse files
ttaylorrgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6885cd7 commit 66f52fa

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

pack-revindex.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,8 @@ static int load_revindex_from_disk(char *revindex_name,
253253
*data_p = (const uint32_t *)data;
254254
}
255255

256-
close(fd);
256+
if (fd >= 0)
257+
close(fd);
257258
return ret;
258259
}
259260

0 commit comments

Comments
 (0)