summaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
authorMike Krus <mike.krus@kdab.com>2020-03-03 16:24:51 +0000
committerMike Krus <mike.krus@kdab.com>2020-03-04 06:11:25 +0000
commitfd520c2b9e3c57e4f63c60e6fe27af00b7b427c4 (patch)
tree368237831a87a6a85809ec7f6752c1d32a2f7753 /src/core
parent2f8c7dd69c9d234b03ea0262e5246ceaaaa444db (diff)
Fix memory leaks
Some jobs get skipped because they don't have anything to do. However, since the runnable does not get submitted to the pool, it would leak (along with the job it points to). Also fixed a couple of compile warnings. Change-Id: I7a25649f2f760c0593862328c0ab905da98c982a Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'src/core')
-rw-r--r--src/core/jobs/qthreadpooler.cpp24
-rw-r--r--src/core/jobs/qthreadpooler_p.h1
2 files changed, 20 insertions, 5 deletions
diff --git a/src/core/jobs/qthreadpooler.cpp b/src/core/jobs/qthreadpooler.cpp
index 621881597..f1c2883dc 100644
--- a/src/core/jobs/qthreadpooler.cpp
+++ b/src/core/jobs/qthreadpooler.cpp
@@ -92,15 +92,31 @@ void QThreadPooler::enqueueTasks(const QVector<RunnableInterface *> &tasks)
(*it)->setPooler(this);
m_threadPool->start((*it));
} else {
- release();
- enqueueDepencies(*it);
+ skipTask(*it);
}
}
}
}
+void QThreadPooler::skipTask(RunnableInterface *task)
+{
+ enqueueDepencies(task);
+
+ if (currentCount() == 0) {
+ if (m_futureInterface) {
+ m_futureInterface->reportFinished();
+ delete m_futureInterface;
+ }
+ m_futureInterface = nullptr;
+ }
+
+ delete task; // normally gets deleted by threadpool
+}
+
void QThreadPooler::enqueueDepencies(RunnableInterface *task)
{
+ release();
+
if (task->type() == RunnableInterface::RunnableType::AspectTask) {
AspectTaskRunnable *aspectTask = static_cast<AspectTaskRunnable *>(task);
const auto &dependers = aspectTask->m_dependers;
@@ -113,8 +129,7 @@ void QThreadPooler::enqueueDepencies(RunnableInterface *task)
dependerTask->setPooler(this);
m_threadPool->start(dependerTask);
} else {
- release();
- enqueueDepencies(*it);
+ skipTask(*it);
}
}
}
@@ -126,7 +141,6 @@ void QThreadPooler::taskFinished(RunnableInterface *task)
{
const QMutexLocker locker(&m_mutex);
- release();
m_totalRunJobs++;
enqueueDepencies(task);
diff --git a/src/core/jobs/qthreadpooler_p.h b/src/core/jobs/qthreadpooler_p.h
index fafd549b2..43a67033e 100644
--- a/src/core/jobs/qthreadpooler_p.h
+++ b/src/core/jobs/qthreadpooler_p.h
@@ -81,6 +81,7 @@ public:
private:
void enqueueTasks(const QVector<RunnableInterface *> &tasks);
+ void skipTask(RunnableInterface *task);
void enqueueDepencies(RunnableInterface *task);
void acquire(int add);
void release();