From 715e304f93604659eb91f77ee7224b04fc916c09 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Tue, 19 Jul 2022 15:23:43 +0200 Subject: VcsCommandDecorator: Don't leak future objects Don't leak QFutureInterface and QFutureWatcher in case VcsCommandDecorator was destroyed before the task was finished. Change-Id: Ib915afe29250f3e5c3fe2e1d465005a0c980252b Reviewed-by: Orgad Shaneh --- src/plugins/vcsbase/vcsbaseclient.cpp | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) (limited to 'src/plugins/vcsbase/vcsbaseclient.cpp') diff --git a/src/plugins/vcsbase/vcsbaseclient.cpp b/src/plugins/vcsbase/vcsbaseclient.cpp index c695eb2cb3..685784e842 100644 --- a/src/plugins/vcsbase/vcsbaseclient.cpp +++ b/src/plugins/vcsbase/vcsbaseclient.cpp @@ -47,7 +47,7 @@ #include #include -#include +#include #include #include #include @@ -81,12 +81,14 @@ class VcsCommandDecorator : public QObject { public: VcsCommandDecorator(ShellCommand *command); + ~VcsCommandDecorator(); private: void addTask(const QFuture &future); void postRunCommand(const FilePath &workingDirectory); ShellCommand *m_command; + QFutureInterface m_futureInterface; }; VcsCommandDecorator::VcsCommandDecorator(ShellCommand *command) @@ -121,7 +123,13 @@ VcsCommandDecorator::VcsCommandDecorator(ShellCommand *command) connect(ICore::instance(), &ICore::coreAboutToClose, this, [this, connection] { disconnect(connection); m_command->abort(); - });} + }); +} + +VcsCommandDecorator::~VcsCommandDecorator() +{ + m_futureInterface.reportFinished(); +} void VcsCommandDecorator::addTask(const QFuture &future) { @@ -133,18 +141,7 @@ void VcsCommandDecorator::addTask(const QFuture &future) if (m_command->hasProgressParser()) { ProgressManager::addTask(future, name, id); } else { - // add a timed tasked based on timeout - // we cannot access the future interface directly, so we need to create a new one - // with the same lifetime - auto fi = new QFutureInterface(); - auto watcher = new QFutureWatcher(); - connect(watcher, &QFutureWatcherBase::finished, [fi, watcher] { - fi->reportFinished(); - delete fi; - watcher->deleteLater(); - }); - watcher->setFuture(future); - ProgressManager::addTimedTask(*fi, name, id, qMax(2, m_command->timeoutS() / 5)); + ProgressManager::addTimedTask(m_futureInterface, name, id, qMax(2, m_command->timeoutS() / 5)); } Internal::VcsPlugin::addFuture(future); -- cgit v1.2.1