From 842ac7c97e26b385c3d7c3d9743911e84808238a Mon Sep 17 00:00:00 2001 From: Enno Boland Date: Mon, 20 Jun 2016 10:03:49 +0200 Subject: [PATCH] lib/util_hash.c: fix memleak. --- lib/util_hash.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/util_hash.c b/lib/util_hash.c index 1c1060b9..985e9063 100644 --- a/lib/util_hash.c +++ b/lib/util_hash.c @@ -123,10 +123,12 @@ xbps_file_hash_raw(const char *file) SHA256_Init(&sha256); while ((len = read(fd, buf, sizeof(buf))) > 0) SHA256_Update(&sha256, buf, len); + if(len < 0) { + free(digest); + return NULL; + } SHA256_Final(digest, &sha256); (void)close(fd); - if(len < 0) - return NULL; return digest; }