summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2023-08-07 11:57:18 -0700
committerJunio C Hamano <gitster@pobox.com>2023-08-07 11:57:18 -0700
commitb2797581d0b362059be6e7bed9be98e5cda44e4b (patch)
tree192da63c47d4d9cc83459a753fbcacc5e48e382d
parenta04cef9fd74df0af3f406102897fc265ff53dc1b (diff)
parent823839bda1a72c54fe8ac025fb70dd3403c11f46 (diff)
downloadgit-b2797581d0b362059be6e7bed9be98e5cda44e4b.tar.xz
Merge branch 'ew/sha256-gcrypt-leak-fixes'
Leakfixes. * ew/sha256-gcrypt-leak-fixes: sha256/gcrypt: die on gcry_md_open failures sha256/gcrypt: fix memory leak with SHA-256 repos sha256/gcrypt: fix build with SANITIZE=leak
-rw-r--r--sha256/gcrypt.h13
1 files changed, 8 insertions, 5 deletions
diff --git a/sha256/gcrypt.h b/sha256/gcrypt.h
index 501da5ed91..17a90f1052 100644
--- a/sha256/gcrypt.h
+++ b/sha256/gcrypt.h
@@ -7,22 +7,25 @@
typedef gcry_md_hd_t gcrypt_SHA256_CTX;
-inline void gcrypt_SHA256_Init(gcrypt_SHA256_CTX *ctx)
+static inline void gcrypt_SHA256_Init(gcrypt_SHA256_CTX *ctx)
{
- gcry_md_open(ctx, GCRY_MD_SHA256, 0);
+ gcry_error_t err = gcry_md_open(ctx, GCRY_MD_SHA256, 0);
+ if (err)
+ die("gcry_md_open: %s", gcry_strerror(err));
}
-inline void gcrypt_SHA256_Update(gcrypt_SHA256_CTX *ctx, const void *data, size_t len)
+static inline void gcrypt_SHA256_Update(gcrypt_SHA256_CTX *ctx, const void *data, size_t len)
{
gcry_md_write(*ctx, data, len);
}
-inline void gcrypt_SHA256_Final(unsigned char *digest, gcrypt_SHA256_CTX *ctx)
+static inline void gcrypt_SHA256_Final(unsigned char *digest, gcrypt_SHA256_CTX *ctx)
{
memcpy(digest, gcry_md_read(*ctx, GCRY_MD_SHA256), SHA256_DIGEST_SIZE);
+ gcry_md_close(*ctx);
}
-inline void gcrypt_SHA256_Clone(gcrypt_SHA256_CTX *dst, const gcrypt_SHA256_CTX *src)
+static inline void gcrypt_SHA256_Clone(gcrypt_SHA256_CTX *dst, const gcrypt_SHA256_CTX *src)
{
gcry_md_copy(dst, *src);
}