Commit 26d138af72 for openssl.org

commit 26d138af724961c5f30263c15ae8137d4f86645b
Author: Niels Dossche <niels.dossche@ugent.be>
Date:   Mon Dec 8 15:17:56 2025 +0100

    Fix memory leak in error path of ec_gen_init()

    ec_gen_set_params() can fail after some big numbers have already been
    copied over. Those need to be cleaned to avoid a memory leak on failure.
    This can be done with ec_gen_cleanup(), which is also consistent in how
    the ecx_gen code does it.

    Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
    Reviewed-by: Tomas Mraz <tomas@openssl.org>
    (Merged from https://github.com/openssl/openssl/pull/29335)

diff --git a/providers/implementations/keymgmt/ec_kmgmt.c b/providers/implementations/keymgmt/ec_kmgmt.c
index 7e9b723622..cc3cf75cd8 100644
--- a/providers/implementations/keymgmt/ec_kmgmt.c
+++ b/providers/implementations/keymgmt/ec_kmgmt.c
@@ -985,7 +985,7 @@ static void *ec_gen_init(void *provctx, int selection,
         gctx->ecdh_mode = 0;
         OSSL_FIPS_IND_INIT(gctx)
         if (!ec_gen_set_params(gctx, params)) {
-            OPENSSL_free(gctx);
+            ec_gen_cleanup(gctx);
             gctx = NULL;
         }
     }