From: Neil Horman Date: Fri, 26 Jun 2026 15:17:09 +0000 (-0400) Subject: use evp_keymgmt_free in keymgmt_from_algorithm X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=4c48ed73190fe282feb3858bdc48dd5fa8d03b96;p=thirdparty%2Fopenssl.git 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ý Reviewed-by: Eugene Syromiatnikov Reviewed-by: Norbert Pocs 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 a84c6344419..3a6a5d06449 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; }