]> git.ipfire.org Git - thirdparty/git.git/commitdiff
pack-mtimes: avoid closing a bogus file descriptor
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Wed, 15 Jun 2022 23:35:43 +0000 (23:35 +0000)
committerJunio C Hamano <gitster@pobox.com>
Thu, 16 Jun 2022 20:22:03 +0000 (13:22 -0700)
In 94cd775a6c52 (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 <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
pack-mtimes.c

index 0e0aafdcb061cd2e93f8d594e2d2d3d8da7636bf..0f9785fc5e4ed9c26f7c1f5503395e74da0d74b3 100644 (file)
@@ -89,7 +89,8 @@ cleanup:
                *data_p = data;
        }
 
-       close(fd);
+       if (fd >= 0)
+               close(fd);
        return ret;
 }