pack-mtimes: avoid closing a bogus file descriptor

In 94cd775a6c (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>
This commit is contained in:
Johannes Schindelin 2022-06-15 23:35:43 +00:00 committed by Junio C Hamano
parent 652891de4f
commit 41f1a8e6a4
1 changed files with 2 additions and 1 deletions

View File

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