Skip to content

Commit b279758

Browse files
committed
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
2 parents a04cef9 + 823839b commit b279758

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

sha256/gcrypt.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,25 @@
77

88
typedef gcry_md_hd_t gcrypt_SHA256_CTX;
99

10-
inline void gcrypt_SHA256_Init(gcrypt_SHA256_CTX *ctx)
10+
static inline void gcrypt_SHA256_Init(gcrypt_SHA256_CTX *ctx)
1111
{
12-
gcry_md_open(ctx, GCRY_MD_SHA256, 0);
12+
gcry_error_t err = gcry_md_open(ctx, GCRY_MD_SHA256, 0);
13+
if (err)
14+
die("gcry_md_open: %s", gcry_strerror(err));
1315
}
1416

15-
inline void gcrypt_SHA256_Update(gcrypt_SHA256_CTX *ctx, const void *data, size_t len)
17+
static inline void gcrypt_SHA256_Update(gcrypt_SHA256_CTX *ctx, const void *data, size_t len)
1618
{
1719
gcry_md_write(*ctx, data, len);
1820
}
1921

20-
inline void gcrypt_SHA256_Final(unsigned char *digest, gcrypt_SHA256_CTX *ctx)
22+
static inline void gcrypt_SHA256_Final(unsigned char *digest, gcrypt_SHA256_CTX *ctx)
2123
{
2224
memcpy(digest, gcry_md_read(*ctx, GCRY_MD_SHA256), SHA256_DIGEST_SIZE);
25+
gcry_md_close(*ctx);
2326
}
2427

25-
inline void gcrypt_SHA256_Clone(gcrypt_SHA256_CTX *dst, const gcrypt_SHA256_CTX *src)
28+
static inline void gcrypt_SHA256_Clone(gcrypt_SHA256_CTX *dst, const gcrypt_SHA256_CTX *src)
2629
{
2730
gcry_md_copy(dst, *src);
2831
}

0 commit comments

Comments
 (0)