Commit 89bd896a1e for openssl.org
commit 89bd896a1e7439c3c5f2d3cf89a10f34aae4adad
Author: s-sharar <ssharar@uwaterloo.ca>
Date: Sun Nov 15 16:39:10 2026 -0500
crypto/store/store_meth.c: fix leak of legacy loaders in OSSL_STORE_LOADER_free()
Since commit 2d71463446b2 "Makle STORE_LOADER not do ref counting"
(which, in turn, was a fix for commit 2d71463446b2 "Makle STORE_LOADER
not do ref counting"), OSSL_STORE_LOADER_free() only frees loaders
that are not kept in the method store. Loaders made with the deprecated
OSSL_STORE_LOADER_new() have no provider and are never in the method
store, so they were leaked. Free them as well, and add a test.
Resolves: https://github.com/openssl/openssl/issues/33635
Fixes: 2d71463446b2 "Makle STORE_LOADER not do ref counting"
Complements: 8c8a80b00ba1 "Extend refcounting on evp objects to provider requesed no-caching"
Assisted-by: Claude Code:claude-fable-5-2
Reviewed-by: Matt Caswell <matt@openssl.foundation>
Reviewed-by: Eugene Syromiatnikov <esyr@openssl.org>
Merge-date: Fri Nov 20 15:04:40 2026
Merged-from: https://github.com/openssl/openssl/pull/33754
diff --git a/crypto/store/store_meth.c b/crypto/store/store_meth.c
index 5b2b6ac57f..b0c5121319 100644
--- a/crypto/store/store_meth.c
+++ b/crypto/store/store_meth.c
@@ -58,7 +58,8 @@ void OSSL_STORE_LOADER_free(OSSL_STORE_LOADER *loader)
#ifdef OPENSSL_NO_CACHED_FETCH
free_loader(loader);
#else
- if (loader != NULL && (loader->no_store != 0))
+ /* Legacy loaders have no provider and are never in the method store */
+ if (loader != NULL && (loader->no_store != 0 || loader->prov == NULL))
free_loader(loader);
#endif
}
diff --git a/test/ossl_store_test.c b/test/ossl_store_test.c
index 6cc79ff09d..7ab1264b95 100644
--- a/test/ossl_store_test.c
+++ b/test/ossl_store_test.c
@@ -7,6 +7,9 @@
* https://www.openssl.org/source/license.html
*/
+/* We need to use some deprecated APIs */
+#define OPENSSL_SUPPRESS_DEPRECATED
+
#include <string.h>
#include <limits.h>
#include <openssl/store.h>
@@ -709,6 +712,19 @@ err:
return ret;
}
+#ifndef OPENSSL_NO_DEPRECATED_3_0
+static int test_store_legacy_loader_free(void)
+{
+ OSSL_STORE_LOADER *loader = NULL;
+
+ if (!TEST_ptr(loader = OSSL_STORE_LOADER_new(NULL, "legacyfree")))
+ return 0;
+
+ OSSL_STORE_LOADER_free(loader);
+ return 1;
+}
+#endif
+
const OPTIONS *test_get_options(void)
{
static const OPTIONS test_options[] = {
@@ -782,6 +798,9 @@ int setup_tests(void)
ADD_TEST(test_fake_store_attach);
ADD_TEST(test_fake_store_delete);
ADD_TEST(test_fake_store_skey_ref);
+#ifndef OPENSSL_NO_DEPRECATED_3_0
+ ADD_TEST(test_store_legacy_loader_free);
+#endif
return 1;
}