md_rand.c thread safety
[openssl.git] / crypto / cryptlib.c
index 5871216b0b97846757c566040a6185731b88e728..be83f5617f5f076c671a3f362eb9d753d1e43076 100644 (file)
@@ -90,6 +90,7 @@ static const char* lock_names[CRYPTO_NUM_LOCKS] =
        "ssl_sess_cert",
        "ssl",
        "rand",
+       "rand2",
        "debug_malloc",
        "BIO",
        "gethostbyname",
@@ -102,7 +103,7 @@ static const char* lock_names[CRYPTO_NUM_LOCKS] =
        "dynlock",
        "engine",
        "ui",
-#if CRYPTO_NUM_LOCKS != 30
+#if CRYPTO_NUM_LOCKS != 31
 # error "Inconsistency between crypto.h and cryptlib.c"
 #endif
        };
@@ -242,7 +243,7 @@ void CRYPTO_destroy_dynlockid(int i)
                        }
                else
 #endif
-                       if (--(pointer->references) <= 0)
+                       if (pointer->references <= 0)
                                {
                                sk_CRYPTO_dynlock_set(dyn_locks, i, NULL);
                                }
@@ -397,16 +398,15 @@ void CRYPTO_lock(int mode, int type, const char *file, int line)
 #endif
        if (type < 0)
                {
-               int i = -type - 1;
                struct CRYPTO_dynlock_value *pointer
-                       = CRYPTO_get_dynlock_value(i);
+                       = CRYPTO_get_dynlock_value(type);
 
-               if (pointer)
+               if (pointer && dynlock_lock_callback)
                        {
                        dynlock_lock_callback(mode, pointer, file, line);
                        }
 
-               CRYPTO_destroy_dynlockid(i);
+               CRYPTO_destroy_dynlockid(type);
                }
        else
                if (locking_callback != NULL)
@@ -432,7 +432,6 @@ int CRYPTO_add_lock(int *pointer, int amount, int type, const char *file,
                        CRYPTO_get_lock_name(type),
                        file,line);
 #endif
-               *pointer=ret;
                }
        else
                {