Commit 34f0fe9d authored by Richard Levitte's avatar Richard Levitte
Browse files

Avoid a race condition if another thread happens to remove the error

state at the same time.
parent ccb9aae9
Loading
Loading
Loading
Loading
+8 −5
Original line number Original line Diff line number Diff line
@@ -652,6 +652,8 @@ void ERR_remove_state(unsigned long pid)
		pid=(unsigned long)CRYPTO_thread_id();
		pid=(unsigned long)CRYPTO_thread_id();
	tmp.pid=pid;
	tmp.pid=pid;
	CRYPTO_w_lock(CRYPTO_LOCK_ERR);
	CRYPTO_w_lock(CRYPTO_LOCK_ERR);
	if (thread_hash)
		{
		p=(ERR_STATE *)lh_delete(thread_hash,&tmp);
		p=(ERR_STATE *)lh_delete(thread_hash,&tmp);
		if (lh_num_items(thread_hash) == 0)
		if (lh_num_items(thread_hash) == 0)
			{
			{
@@ -659,6 +661,7 @@ void ERR_remove_state(unsigned long pid)
			lh_free(thread_hash);
			lh_free(thread_hash);
			thread_hash = NULL;
			thread_hash = NULL;
			}
			}
		}
	CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
	CRYPTO_w_unlock(CRYPTO_LOCK_ERR);


	if (p != NULL) ERR_STATE_free(p);
	if (p != NULL) ERR_STATE_free(p);