From: Johannes Schindelin Date: Wed, 15 Jun 2022 23:35:43 +0000 (+0000) Subject: pack-mtimes: avoid closing a bogus file descriptor X-Git-Tag: v2.37.0-rc1~7^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=41f1a8e6a417bc3e56a0eef687e28247138276d1;p=thirdparty%2Fgit.git pack-mtimes: avoid closing a bogus file descriptor 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 Signed-off-by: Junio C Hamano --- diff --git a/pack-mtimes.c b/pack-mtimes.c index 0e0aafdcb0..0f9785fc5e 100644 --- a/pack-mtimes.c +++ b/pack-mtimes.c @@ -89,7 +89,8 @@ cleanup: *data_p = data; } - close(fd); + if (fd >= 0) + close(fd); return ret; }