Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix memory leak in task manager widget
  • Loading branch information
nyalldawson committed Feb 20, 2018
1 parent 64369f8 commit 5c06166
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/core/qgstaskmanager.cpp
Expand Up @@ -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 )
Expand Down Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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 );
}

Expand Down Expand Up @@ -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
}
1 change: 1 addition & 0 deletions src/core/qgstaskmanager.h
Expand Up @@ -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;
Expand Down

0 comments on commit 5c06166

Please sign in to comment.