]> xenbits.xensource.com Git - libvirt.git/commitdiff
Threadpool: Initialize new dynamic workers
authorMichal Privoznik <mprivozn@redhat.com>
Wed, 7 Sep 2011 12:08:14 +0000 (14:08 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 7 Sep 2011 12:23:26 +0000 (14:23 +0200)
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

index 70a75c05125ed10a51df48f0050610ccbccd19de..c16e2aff6046d521656368e631e39212feb20606 100644 (file)
@@ -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,20 @@ 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) {
+            VIR_FREE(data);
             pool->nWorkers--;
             goto error;
         }