Commit 4c48ed7319 for openssl.org

commit 4c48ed73190fe282feb3858bdc48dd5fa8d03b96
Author: Neil Horman <nhorman@openssl.org>
Date:   Fri Jun 26 11:17:09 2026 -0400

    use evp_keymgmt_free in keymgmt_from_algorithm

    keymgmt_from_algorithm, in its error path frees the allocated keymgmt
    with EVP_KEYMGMT_free, but thats a no-op now, and we actually want to
    free it to avoid leaks, so we should use evp_keymgmt_free (the internal
    function that acutally does free the alg) instead.

    Fixes https://scan5.scan.coverity.com/#/project-view/60762/10222?selectedIssue=1695452

    Reviewed-by: Saša NedvÄ›dický <sashan@openssl.org>
    Reviewed-by: Eugene Syromiatnikov <esyr@openssl.org>
    Reviewed-by: Norbert Pocs <norbertp@openssl.org>
    MergeDate: Wed Jul  1 15:32:21 2026
    (Merged from https://github.com/openssl/openssl/pull/31748)

diff --git a/crypto/evp/keymgmt_meth.c b/crypto/evp/keymgmt_meth.c
index a84c634441..3a6a5d0644 100644
--- a/crypto/evp/keymgmt_meth.c
+++ b/crypto/evp/keymgmt_meth.c
@@ -50,7 +50,7 @@ static void *keymgmt_new(void)
     if ((keymgmt = OPENSSL_zalloc(sizeof(*keymgmt))) == NULL)
         return NULL;
     if (!CRYPTO_NEW_REF(&keymgmt->refcnt, 1)) {
-        EVP_KEYMGMT_free(keymgmt);
+        OPENSSL_free(keymgmt);
         return NULL;
     }
     return keymgmt;
@@ -93,7 +93,7 @@ static void *keymgmt_from_algorithm(int name_id,

     keymgmt->name_id = name_id;
     if ((keymgmt->type_name = ossl_algorithm_get1_first_name(algodef)) == NULL) {
-        EVP_KEYMGMT_free(keymgmt);
+        evp_keymgmt_free(keymgmt);
         return NULL;
     }
     keymgmt->description = algodef->algorithm_description;
@@ -269,13 +269,13 @@ static void *keymgmt_from_algorithm(int name_id,
         || (keymgmt->gen != NULL
             && (keymgmt->gen_init == NULL
                 || keymgmt->gen_cleanup == NULL))) {
-        EVP_KEYMGMT_free(keymgmt);
+        evp_keymgmt_free(keymgmt);
         ERR_raise(ERR_LIB_EVP, EVP_R_INVALID_PROVIDER_FUNCTIONS);
         return NULL;
     }
     keymgmt->prov = prov;
     if (prov != NULL && !ossl_provider_up_ref(prov)) {
-        EVP_KEYMGMT_free(keymgmt);
+        evp_keymgmt_free(keymgmt);
         ERR_raise(ERR_LIB_EVP, EVP_R_INITIALIZATION_ERROR);
         return NULL;
     }