summaryrefslogtreecommitdiff
path: root/pack-mtimes.c
diff options
context:
space:
mode:
authorJohannes Schindelin <johannes.schindelin@gmx.de>2022-06-15 23:35:43 (GMT)
committerJunio C Hamano <gitster@pobox.com>2022-06-16 20:22:03 (GMT)
commit41f1a8e6a417bc3e56a0eef687e28247138276d1 (patch)
treec14f4396511c8d270b66516f4c58196949ae0cc8 /pack-mtimes.c
parent652891de4ff164d545daa5472ab67f4f9d41319b (diff)
downloadgit-41f1a8e6a417bc3e56a0eef687e28247138276d1.zip
git-41f1a8e6a417bc3e56a0eef687e28247138276d1.tar.gz
git-41f1a8e6a417bc3e56a0eef687e28247138276d1.tar.bz2
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 <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'pack-mtimes.c')
-rw-r--r--pack-mtimes.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/pack-mtimes.c b/pack-mtimes.c
index 0e0aafd..0f9785f 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;
}