From fd520c2b9e3c57e4f63c60e6fe27af00b7b427c4 Mon Sep 17 00:00:00 2001 From: Mike Krus Date: Tue, 3 Mar 2020 16:24:51 +0000 Subject: 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 --- src/core/jobs/qthreadpooler.cpp | 24 +++++++++++++++++++----- src/core/jobs/qthreadpooler_p.h | 1 + 2 files changed, 20 insertions(+), 5 deletions(-) (limited to 'src/core') 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 &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(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 &tasks); + void skipTask(RunnableInterface *task); void enqueueDepencies(RunnableInterface *task); void acquire(int add); void release(); -- cgit v1.2.3