Skip to content
Permalink
Browse files

Fix memory leak in task manager widget

  • Loading branch information
nyalldawson committed Feb 20, 2018
1 parent 64369f8 commit 5c061668f7c42c9abc374abdf3ce9891996b2e45
Showing with 12 additions and 3 deletions.
  1. +11 −3 src/core/qgstaskmanager.cpp
  2. +1 −0 src/core/qgstaskmanager.h
@@ -644,7 +644,8 @@ void QgsTaskManager::taskStatusChanged( int status )
mTaskMutex->lock();
QgsTaskRunnableWrapper *runnable = mTasks.value( id ).runnable;
mTaskMutex->unlock();
QThreadPool::globalInstance()->cancel( runnable );
if ( runnable )
QThreadPool::globalInstance()->cancel( runnable );
#endif

if ( status == QgsTask::Terminated || status == QgsTask::Complete )
@@ -748,7 +749,8 @@ bool QgsTaskManager::cleanupAndDeleteTask( QgsTask *task )
else
{
#if QT_VERSION >= 0x050500
QThreadPool::globalInstance()->cancel( runnable );
if ( runnable )
QThreadPool::globalInstance()->cancel( runnable );
#endif
if ( isParent )
{
@@ -780,6 +782,7 @@ void QgsTaskManager::processQueue()
QgsTask *task = it.value().task;
if ( task && task->mStatus == QgsTask::Queued && dependenciesSatisfied( it.key() ) && it.value().added.testAndSetRelaxed( 0, 1 ) )
{
it.value().createRunnable();
QThreadPool::globalInstance()->start( it.value().runnable, it.value().priority );
}

@@ -834,5 +837,10 @@ QgsTaskManager::TaskInfo::TaskInfo( QgsTask *task, int priority )
: task( task )
, added( 0 )
, priority( priority )
, runnable( new QgsTaskRunnableWrapper( task ) )
{}

void QgsTaskManager::TaskInfo::createRunnable()
{
Q_ASSERT( !runnable );
runnable = new QgsTaskRunnableWrapper( task ); // auto deleted
}
@@ -559,6 +559,7 @@ class CORE_EXPORT QgsTaskManager : public QObject
struct TaskInfo
{
TaskInfo( QgsTask *task = nullptr, int priority = 0 );
void createRunnable();
QgsTask *task = nullptr;
QAtomicInt added;
int priority;

0 comments on commit 5c06166

Please sign in to comment.
You can’t perform that action at this time.