Fixed deadlock in CRYPTO_THREAD_run_once for Windows
authorDK <dmitrykos@neutroncode.com>
Sun, 13 Nov 2016 12:48:15 +0000 (14:48 +0200)
committerRich Salz <rsalz@openssl.org>
Sun, 13 Nov 2016 20:43:05 +0000 (15:43 -0500)
Fixed deadlock in CRYPTO_THREAD_run_once() if call to init() is causing
a recursive call to CRYPTO_THREAD_run_once() again that is causing a hot
deadloop inside do { } while (result == ONCE_ININIT); section.

CLA: trivial
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/1913)

crypto/threads_win.c

index 4e0de90..5347c9e 100644 (file)
@@ -78,8 +78,8 @@ int CRYPTO_THREAD_run_once(CRYPTO_ONCE *once, void (*init)(void))
     do {
         result = InterlockedCompareExchange(lock, ONCE_ININIT, ONCE_UNINITED);
         if (result == ONCE_UNINITED) {
-            init();
             *lock = ONCE_DONE;
+            init();
             return 1;
         }
     } while (result == ONCE_ININIT);