1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-07 17:28:15 +00:00

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.
This commit is contained in:
Michal Privoznik 2011-09-07 14:08:14 +02:00
parent a6e2ef732d
commit d1a366be05

View File

@ -286,6 +286,7 @@ int virThreadPoolSendJob(virThreadPoolPtr pool,
void *jobData) void *jobData)
{ {
virThreadPoolJobPtr job; virThreadPoolJobPtr job;
struct virThreadPoolWorkerData *data = NULL;
virMutexLock(&pool->mutex); virMutexLock(&pool->mutex);
if (pool->quit) if (pool->quit)
@ -298,10 +299,20 @@ int virThreadPoolSendJob(virThreadPoolPtr pool,
goto error; 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], if (virThreadCreate(&pool->workers[pool->nWorkers - 1],
true, true,
virThreadPoolWorker, virThreadPoolWorker,
pool) < 0) { data) < 0) {
VIR_FREE(data);
pool->nWorkers--; pool->nWorkers--;
goto error; goto error;
} }