You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by yl...@apache.org on 2021/09/09 23:43:44 UTC

svn commit: r1893199 - /apr/apr/trunk/crypto/apr_crypto_prng.c

Author: ylavic
Date: Thu Sep  9 23:43:44 2021
New Revision: 1893199

URL: http://svn.apache.org/viewvc?rev=1893199&view=rev
Log:
apr_crypto: fixes for thread local storage destructor.

cprng_thread_destroy() should destroy the given cprng first because
this might set cprng_global to NULL.

apr_crypto_prng_init() shouldn't delete cprng_thread_key on failure
unless APR_CRYPTO_PRNG_PER_THREAD is used.

Modified:
    apr/apr/trunk/crypto/apr_crypto_prng.c

Modified: apr/apr/trunk/crypto/apr_crypto_prng.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/crypto/apr_crypto_prng.c?rev=1893199&r1=1893198&r2=1893199&view=diff
==============================================================================
--- apr/apr/trunk/crypto/apr_crypto_prng.c (original)
+++ apr/apr/trunk/crypto/apr_crypto_prng.c Thu Sep  9 23:43:44 2021
@@ -112,11 +112,14 @@ static apr_threadkey_t *cprng_thread_key
 
 static void cprng_thread_destroy(void *cprng)
 {
+    apr_threadkey_private_set(NULL, cprng_thread_key);
+    if (cprng) {
+        apr_crypto_prng_destroy(cprng);
+    }
     if (!cprng_global) {
         apr_threadkey_private_delete(cprng_thread_key);
         cprng_thread_key = NULL;
     }
-    apr_crypto_prng_destroy(cprng);
 }
 
 #else  /* !APR_HAS_THREADS */
@@ -157,8 +160,10 @@ APR_DECLARE(apr_status_t) apr_crypto_prn
     rv = apr_thread_mutex_create(&cprng_ring_mutex, APR_THREAD_MUTEX_DEFAULT,
                                  pool);
     if (rv != APR_SUCCESS) {
-        apr_threadkey_private_delete(cprng_thread_key);
-        cprng_thread_key = NULL;
+        if (flags & APR_CRYPTO_PRNG_PER_THREAD) {
+            apr_threadkey_private_delete(cprng_thread_key);
+            cprng_thread_key = NULL;
+        }
         return rv;
     }