commit: 6480394a50b1be7632ce414ca8d956484eac51f2
Author: Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Fri Jan 15 20:03:51 2021 +0000
Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Fri Jan 15 20:03:51 2021 +0000
URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=6480394a
libq/hash: close fd once in hash_multiple_file_fd
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>
libq/hash.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/libq/hash.c b/libq/hash.c
index 88c4b56..b5aec46 100644
--- a/libq/hash.c
+++ b/libq/hash.c
@@ -147,6 +147,7 @@ hash_multiple_file_fd(
(void)blak2b;
#endif
+ *flen = 0;
if ((f = fdopen(fd, "r")) == NULL)
return -1;
@@ -164,7 +165,6 @@ hash_multiple_file_fd(
blake2b_init(&bl2b, BLAKE2B_OUTBYTES);
#endif
- *flen = 0;
while ((len = fread(data, 1, sizeof(data), f)) > 0) {
*flen += len;
#pragma omp parallel sections
@@ -323,7 +323,9 @@ hash_multiple_file_at_cb(
ret = hash_multiple_file_fd(fd, md5, sha1, sha256, sha512,
whrlpl, blak2b, flen, hashes);
- close(fd);
+ if (ret != 0)
+ close(fd);
+
return ret;
}