]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
use evp_keymgmt_free in keymgmt_from_algorithm
authorNeil Horman <nhorman@openssl.org>
Fri, 26 Jun 2026 15:17:09 +0000 (11:17 -0400)
committerNeil Horman <nhorman@openssl.org>
Wed, 1 Jul 2026 15:32:12 +0000 (11:32 -0400)
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)

crypto/evp/keymgmt_meth.c

index a84c6344419aa29bd31ef57c35f6845d3eb08009..3a6a5d06449d4a54cf519bd88adc2392d9a853f2 100644 (file)
@@ -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;
     }