Git fork

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

+8 -5
+8 -5
sha256/gcrypt.h
··· 7 7 8 8 typedef gcry_md_hd_t gcrypt_SHA256_CTX; 9 9 10 - inline void gcrypt_SHA256_Init(gcrypt_SHA256_CTX *ctx) 10 + static inline void gcrypt_SHA256_Init(gcrypt_SHA256_CTX *ctx) 11 11 { 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)); 13 15 } 14 16 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) 16 18 { 17 19 gcry_md_write(*ctx, data, len); 18 20 } 19 21 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) 21 23 { 22 24 memcpy(digest, gcry_md_read(*ctx, GCRY_MD_SHA256), SHA256_DIGEST_SIZE); 25 + gcry_md_close(*ctx); 23 26 } 24 27 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) 26 29 { 27 30 gcry_md_copy(dst, *src); 28 31 }