mac_legacy_kmgmt.c: Avoid possible memory leak on error

Use mac_gen_cleanup() instead of just freeing the gctx.
Fixes Coverity 1638702

Reviewed-by: Neil Horman <nhorman@openssl.org>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/26500)

(cherry picked from commit 2455ef2112)
This commit is contained in:
Tomas Mraz 2025-01-21 14:38:23 +01:00
parent 78e8819f17
commit 75b03b00e2

View file

@ -393,7 +393,7 @@ static void *mac_gen_init(void *provctx, int selection,
struct mac_gen_ctx *gctx = mac_gen_init_common(provctx, selection);
if (gctx != NULL && !mac_gen_set_params(gctx, params)) {
OPENSSL_free(gctx);
mac_gen_cleanup(gctx);
gctx = NULL;
}
return gctx;
@ -405,7 +405,7 @@ static void *cmac_gen_init(void *provctx, int selection,
struct mac_gen_ctx *gctx = mac_gen_init_common(provctx, selection);
if (gctx != NULL && !cmac_gen_set_params(gctx, params)) {
OPENSSL_free(gctx);
mac_gen_cleanup(gctx);
gctx = NULL;
}
return gctx;