From 537f5fe589de03685aa2cb717675f681246bc548 Mon Sep 17 00:00:00 2001 From: Brian Olsen Date: Tue, 10 Aug 2021 16:37:02 +0000 Subject: [PATCH] jws: _cjose_jws_build_dig_sha: fix jws->dig reuse memory leak --- src/jws.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/jws.c b/src/jws.c index 4e03554..dbbdc1e 100644 --- a/src/jws.c +++ b/src/jws.c @@ -173,8 +173,8 @@ static bool _cjose_jws_build_dig_sha(cjose_jws_t *jws, const cjose_jwk_t *jwk, c if (NULL != jws->dig) { - cjose_get_dealloc()(jws->dig); - jws->dig = NULL; + cjose_get_dealloc()(jws->dig); + jws->dig = NULL; } // allocate buffer for digest @@ -264,6 +264,12 @@ static bool _cjose_jws_build_dig_hmac_sha(cjose_jws_t *jws, const cjose_jwk_t *j goto _cjose_jws_build_dig_hmac_sha_cleanup; } + if (NULL != jws->dig) + { + cjose_get_dealloc()(jws->dig); + jws->dig = NULL; + } + // allocate buffer for digest jws->dig_len = EVP_MD_size(digest_alg); jws->dig = (uint8_t *)cjose_get_alloc()(jws->dig_len);