Avoid a race condition if another thread happens to remove the error
authorRichard Levitte <levitte@openssl.org>
Tue, 25 Jul 2000 16:56:39 +0000 (16:56 +0000)
committerRichard Levitte <levitte@openssl.org>
Tue, 25 Jul 2000 16:56:39 +0000 (16:56 +0000)
state at the same time.

crypto/err/err.c

index ad062a9022935881345c6f3308c47d6908782f63..7ce9e8fb9aacd62b8f307032561a63daadcced4f 100644 (file)
@@ -652,12 +652,15 @@ void ERR_remove_state(unsigned long pid)
                pid=(unsigned long)CRYPTO_thread_id();
        tmp.pid=pid;
        CRYPTO_w_lock(CRYPTO_LOCK_ERR);
                pid=(unsigned long)CRYPTO_thread_id();
        tmp.pid=pid;
        CRYPTO_w_lock(CRYPTO_LOCK_ERR);
-       p=(ERR_STATE *)lh_delete(thread_hash,&tmp);
-       if (lh_num_items(thread_hash) == 0)
+       if (thread_hash)
                {
                {
-               /* make sure we don't leak memory */
-               lh_free(thread_hash);
-               thread_hash = NULL;
+               p=(ERR_STATE *)lh_delete(thread_hash,&tmp);
+               if (lh_num_items(thread_hash) == 0)
+                       {
+                       /* make sure we don't leak memory */
+                       lh_free(thread_hash);
+                       thread_hash = NULL;
+                       }
                }
        CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
 
                }
        CRYPTO_w_unlock(CRYPTO_LOCK_ERR);