Skip to content

Commit

Permalink
sha256/gcrypt: fix memory leak with SHA-256 repos
Browse files Browse the repository at this point in the history
`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>
  • Loading branch information
Eric Wong authored and gitster committed Jul 31, 2023
1 parent b4b85e4 commit 8b608f3
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions sha256/gcrypt.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 8b608f3

Please sign in to comment.