]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Add a test to confirm that we can repeatedly create and destroy keys
authorNeil Horman <nhorman@openssl.org>
Thu, 5 Jun 2025 12:54:56 +0000 (08:54 -0400)
committerNeil Horman <nhorman@openssl.org>
Fri, 6 Jun 2025 17:49:39 +0000 (13:49 -0400)
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Saša Nedvědický <sashan@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/27775)

test/threadstest.c

index e30a3e817d8c8b476fd558795e9ab19e58290b02..76db07f3baf6b6d1182fca981de7b2a029691306 100644 (file)
@@ -590,6 +590,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;
@@ -1339,6 +1362,7 @@ int setup_tests(void)
 #endif
     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);