[libvirt] [PATCH] Threadpool: Initialize new dynamic workers

Michal Privoznik mprivozn at redhat.com
Wed Sep 7 12:11:14 UTC 2011


Although we were initializing worker threads during pool creating,
we missed this during virThreadPoolSendJob. This bug led to segmenation
fault as worker thread free() given argument.
---
 src/util/threadpool.c |   13 ++++++++++++-
 1 files changed, 12 insertions(+), 1 deletions(-)

diff --git a/src/util/threadpool.c b/src/util/threadpool.c
index 70a75c0..6210b00 100644
--- a/src/util/threadpool.c
+++ b/src/util/threadpool.c
@@ -286,6 +286,7 @@ int virThreadPoolSendJob(virThreadPoolPtr pool,
                          void *jobData)
 {
     virThreadPoolJobPtr job;
+    struct virThreadPoolWorkerData *data = NULL;
 
     virMutexLock(&pool->mutex);
     if (pool->quit)
@@ -298,10 +299,19 @@ int virThreadPoolSendJob(virThreadPoolPtr pool,
             goto error;
         }
 
+        if (VIR_ALLOC(data) < 0) {
+            pool->nWorkers--;
+            virReportOOMError();
+            goto error;
+        }
+
+        data->pool = pool;
+        data->cond = &pool->cond;
+
         if (virThreadCreate(&pool->workers[pool->nWorkers - 1],
                             true,
                             virThreadPoolWorker,
-                            pool) < 0) {
+                            data) < 0) {
             pool->nWorkers--;
             goto error;
         }
@@ -336,6 +346,7 @@ int virThreadPoolSendJob(virThreadPoolPtr pool,
     return 0;
 
 error:
+    VIR_FREE(data);
     virMutexUnlock(&pool->mutex);
     return -1;
 }
-- 
1.7.3.4




More information about the libvir-list mailing list