From d1a366be055ac4523ffb3db87118882e2f26864f Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Wed, 7 Sep 2011 14:08:14 +0200 Subject: [PATCH] Threadpool: Initialize new dynamic workers 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 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/util/threadpool.c b/src/util/threadpool.c index 70a75c0512..c16e2aff60 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,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; } -- 2.39.5