]> git.ipfire.org Git - thirdparty/git.git/commitdiff
pack-revindex.c: don't close unopened file descriptors
authorTaylor Blau <me@ttaylorr.com>
Fri, 26 Feb 2021 16:31:02 +0000 (11:31 -0500)
committerJunio C Hamano <gitster@pobox.com>
Fri, 26 Feb 2021 22:42:27 +0000 (14:42 -0800)
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>
pack-revindex.c

index 83fe4de77382a1089b62972e3fa5d7771c1a0790..4262530449aa05c566aa231d26bb592d307e2bc1 100644 (file)
@@ -253,7 +253,8 @@ cleanup:
                *data_p = (const uint32_t *)data;
        }
 
-       close(fd);
+       if (fd >= 0)
+               close(fd);
        return ret;
 }