[Asterisk-code-review] threadpool: Fix potential data race. (asterisk[13])

Anonymous Coward asteriskteam at digium.com
Tue May 24 17:34:42 CDT 2016


Anonymous Coward #1000019 has submitted this change and it was merged.

Change subject: threadpool: Fix potential data race.
......................................................................


threadpool: Fix potential data race.

worker_start checked for ZOMBIE status without holding a lock.  All
other read/write of worker status are performed with a lock, so this
check should do the same.

ASTERISK-25777 #close

Change-Id: I5e33685a5c26fdb300851989a3b82be8c4e03781
---
M main/threadpool.c
1 file changed, 3 insertions(+), 1 deletion(-)

Approvals:
  Richard Mudgett: Looks good to me, but someone else must approve
  Anonymous Coward #1000019: Verified
  Joshua Colp: Looks good to me, approved



diff --git a/main/threadpool.c b/main/threadpool.c
index 60e1e9a..9cd33ab 100644
--- a/main/threadpool.c
+++ b/main/threadpool.c
@@ -1012,6 +1012,7 @@
 static void *worker_start(void *arg)
 {
 	struct worker_thread *worker = arg;
+	enum worker_state saved_state;
 
 	if (worker->options.thread_start) {
 		worker->options.thread_start();
@@ -1027,6 +1028,7 @@
 		}
 		threadpool_active_thread_idle(worker->pool, worker);
 	}
+	saved_state = worker->state;
 	ast_mutex_unlock(&worker->lock);
 
 	/* Reaching this portion means the thread is
@@ -1037,7 +1039,7 @@
 	 * that the thread can be removed from the
 	 * list of zombie threads.
 	 */
-	if (worker->state == ZOMBIE) {
+	if (saved_state == ZOMBIE) {
 		threadpool_zombie_thread_dead(worker->pool, worker);
 	}
 

-- 
To view, visit https://gerrit.asterisk.org/2900
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I5e33685a5c26fdb300851989a3b82be8c4e03781
Gerrit-PatchSet: 2
Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Owner: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: Anonymous Coward #1000019
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Richard Mudgett <rmudgett at digium.com>



More information about the asterisk-code-review mailing list