Avoid taking a write lock in RAND_get_rand_method()
[openssl.git] / crypto / rand / rand_lib.c
index 0cdb9caa6ddc56e2dc950c675a6205a3e63830df..9b1b5999cf0499bdcd3bd435e35c386a4832c225 100644 (file)
@@ -189,6 +189,13 @@ const RAND_METHOD *RAND_get_rand_method(void)
     if (!RUN_ONCE(&rand_init, do_rand_init))
         return NULL;
 
+    if (!CRYPTO_THREAD_read_lock(rand_meth_lock))
+        return NULL;
+    tmp_meth = default_RAND_meth;
+    CRYPTO_THREAD_unlock(rand_meth_lock);
+    if (tmp_meth != NULL)
+        return tmp_meth;
+
     if (!CRYPTO_THREAD_write_lock(rand_meth_lock))
         return NULL;
     if (default_RAND_meth == NULL) {