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>
Johannes Schindelin committed
Jun 15, 2022 at 23:35 UTC
41f1a8e6a417bc3e56a0eef687e28247138276d1
1 file changed
+2
-1
pack-mtimes.c
+2
-1
@@ -89,7 +89,8 @@ cleanup:
89
*data_p = data;
90
}
91
92
- close(fd);
92
+ if (fd >= 0)
93
+ close(fd);
94
return ret;
95
}
96