From 54acfafeffa89c1b650c58600e941740d54f9518 Mon Sep 17 00:00:00 2001 From: Neil Horman Date: Thu, 5 Jun 2025 08:54:56 -0400 Subject: [PATCH] Add a test to confirm that we can repeatedly create and destroy keys MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Reviewed-by: Tomas Mraz Reviewed-by: Matt Caswell Reviewed-by: Saša Nedvědický (Merged from https://github.com/openssl/openssl/pull/27775) (cherry picked from commit b994ce4088fb52e769ee5e3e49bdde3030fadaf7) --- test/threadstest.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/threadstest.c b/test/threadstest.c index af0d9d5f664..d85b3ba9ad1 100644 --- a/test/threadstest.c +++ b/test/threadstest.c @@ -182,6 +182,29 @@ static int test_thread_local(void) return 1; } +/* + * Basic test to ensure that we can repeatedly create and + * destroy local keys without leaking anything + */ +static int test_thread_local_multi_key(void) +{ + int dummy; + int i; + + for (i = 0; i < 1000; i++) { + if (!TEST_true(CRYPTO_THREAD_init_local(&thread_local_key, + thread_local_destructor))) + return 0; + + if (!TEST_true(CRYPTO_THREAD_set_local(&thread_local_key, &dummy))) + return 0; + + if (!TEST_true(CRYPTO_THREAD_cleanup_local(&thread_local_key))) + return 0; + } + return 1; +} + static int test_atomic(void) { int val = 0, ret = 0, testresult = 0; @@ -891,6 +914,7 @@ int setup_tests(void) ADD_TEST(test_lock); ADD_TEST(test_once); ADD_TEST(test_thread_local); + ADD_TEST(test_thread_local_multi_key); ADD_TEST(test_atomic); ADD_TEST(test_multi_load); ADD_TEST(test_multi_general_worker_default_provider); -- 2.47.2