From fed8dbea27b7e01ee934951b25c6ffd40ad1d5c3 Mon Sep 17 00:00:00 2001 From: Matt Caswell Date: Thu, 2 Jun 2022 11:14:32 +0100 Subject: [PATCH] Fix a memory leak in ossl_method_store_add() If the call to ossl_prop_defn_set() fails then the OSSL_PROPERTY_LIST we just created will leak. Found as a result of: https://github.com/openssl/openssl/pull/18355#issuecomment-1139499881 Reviewed-by: Tomas Mraz Reviewed-by: Todd Short Reviewed-by: Hugo Landau Reviewed-by: Paul Dale (Merged from https://github.com/openssl/openssl/pull/18458) --- crypto/property/property.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crypto/property/property.c b/crypto/property/property.c index d209f2c79db..fb48022a8f0 100644 --- a/crypto/property/property.c +++ b/crypto/property/property.c @@ -304,7 +304,11 @@ int ossl_method_store_add(OSSL_METHOD_STORE *store, const OSSL_PROVIDER *prov, impl->properties = ossl_parse_property(store->ctx, properties); if (impl->properties == NULL) goto err; - ossl_prop_defn_set(store->ctx, properties, impl->properties); + if (!ossl_prop_defn_set(store->ctx, properties, impl->properties)) { + ossl_property_free(impl->properties); + impl->properties = NULL; + goto err; + } } alg = ossl_method_store_retrieve(store, nid); -- 2.47.2