From: Timo Sirainen Date: Fri, 2 Aug 2024 11:15:23 +0000 (+0300) Subject: lib-dcrypt: ctx_hmac_init() - Fix memory leak if MAC initialization failed X-Git-Tag: 2.4.0~1522 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e77787dd92d5681a428e0abc0f4e349bb9f56685;p=thirdparty%2Fdovecot%2Fcore.git lib-dcrypt: ctx_hmac_init() - Fix memory leak if MAC initialization failed --- diff --git a/src/lib-dcrypt/dcrypt-openssl1.c b/src/lib-dcrypt/dcrypt-openssl1.c index 68671b457a..36bc017a36 100644 --- a/src/lib-dcrypt/dcrypt-openssl1.c +++ b/src/lib-dcrypt/dcrypt-openssl1.c @@ -694,8 +694,10 @@ dcrypt_openssl_ctx_hmac_init(struct dcrypt_context_hmac *ctx, return dcrypt_openssl_error(error_r); #endif ec = HMAC_Init_ex(ctx->ctx, ctx->key, ctx->klen, ctx->md, NULL); - if (ec != 1) + if (ec != 1) { + HMAC_CTX_free(ctx->ctx); return dcrypt_openssl_error(error_r); + } return TRUE; } diff --git a/src/lib-dcrypt/dcrypt-openssl3.c b/src/lib-dcrypt/dcrypt-openssl3.c index 534472d96f..fc783e27d0 100644 --- a/src/lib-dcrypt/dcrypt-openssl3.c +++ b/src/lib-dcrypt/dcrypt-openssl3.c @@ -632,8 +632,10 @@ dcrypt_openssl_ctx_hmac_init(struct dcrypt_context_hmac *ctx, if (ctx->ctx == NULL) return dcrypt_openssl_error(error_r); ec = EVP_MAC_init(ctx->ctx, ctx->key, ctx->klen, params); - if (ec != 1) + if (ec != 1) { + EVP_MAC_CTX_free(ctx->ctx); return dcrypt_openssl_error(error_r); + } return TRUE; }