]> git.ipfire.org Git - thirdparty/git.git/commitdiff
sha256/gcrypt: fix memory leak with SHA-256 repos
authorEric Wong <e@80x24.org>
Mon, 31 Jul 2023 12:08:07 +0000 (12:08 +0000)
committerJunio C Hamano <gitster@pobox.com>
Mon, 31 Jul 2023 15:57:15 +0000 (08:57 -0700)
`gcry_md_open' needs to be paired with `gcry_md_close' to ensure
resources are released.  Since our internal APIs don't have
separate close/release callbacks, sticking it into the finalization
callback seems appropriate.

Building with SANITIZE=leak and running `git fsck' on a SHA-256
repository no longer reports leaks.

Signed-off-by: Eric Wong <e@80x24.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
sha256/gcrypt.h

index 68cf6b6a546a7117385bf763a4ab11838a0e7a6d..1d06a778af1bdccb427528258ac83badb6cc041f 100644 (file)
@@ -20,6 +20,7 @@ static inline void gcrypt_SHA256_Update(gcrypt_SHA256_CTX *ctx, const void *data
 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);
 }
 
 static inline void gcrypt_SHA256_Clone(gcrypt_SHA256_CTX *dst, const gcrypt_SHA256_CTX *src)