OpenSSL: Fix a memory leak on openssl_evp_pkey_ec_prime_len() error path

Fixes: b700a56e14 ("OpenSSL 3.0: Determine the prime length for an EC key group using EVP_PKEY")
Signed-off-by: Chien Wong <m@xv97.com>
This commit is contained in:
Chien Wong 2024-03-05 22:20:40 +08:00 committed by Jouni Malinen
parent 35df7ee09e
commit b35b1036fe

View file

@ -3932,9 +3932,10 @@ static int openssl_evp_pkey_ec_prime_len(struct crypto_ec_key *key)
group = EC_GROUP_new_by_curve_name(nid); group = EC_GROUP_new_by_curve_name(nid);
prime = BN_new(); prime = BN_new();
if (!group || !prime) if (!group || !prime)
return -1; goto fail;
if (EC_GROUP_get_curve(group, prime, NULL, NULL, NULL) == 1) if (EC_GROUP_get_curve(group, prime, NULL, NULL, NULL) == 1)
prime_len = BN_num_bytes(prime); prime_len = BN_num_bytes(prime);
fail:
EC_GROUP_free(group); EC_GROUP_free(group);
BN_free(prime); BN_free(prime);
return prime_len; return prime_len;