summaryrefslogtreecommitdiff
path: root/src/plugins/vcsbase/vcsbaseclient.cpp
diff options
context:
space:
mode:
authorJarek Kobus <jaroslaw.kobus@qt.io>2022-07-19 15:23:43 +0200
committerJarek Kobus <jaroslaw.kobus@qt.io>2022-07-19 13:47:19 +0000
commit715e304f93604659eb91f77ee7224b04fc916c09 (patch)
tree505ec52deed46a05e93bfbef9fc8ca999143e13a /src/plugins/vcsbase/vcsbaseclient.cpp
parent163625f56a32f0fd0cf257b489a59a21f0659678 (diff)
downloadqt-creator-715e304f93604659eb91f77ee7224b04fc916c09.tar.gz
VcsCommandDecorator: Don't leak future objects
Don't leak QFutureInterface<void> and QFutureWatcher<void> in case VcsCommandDecorator was destroyed before the task was finished. Change-Id: Ib915afe29250f3e5c3fe2e1d465005a0c980252b Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Diffstat (limited to 'src/plugins/vcsbase/vcsbaseclient.cpp')
-rw-r--r--src/plugins/vcsbase/vcsbaseclient.cpp25
1 files changed, 11 insertions, 14 deletions
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 <QDebug>
#include <QFileInfo>
-#include <QFutureWatcher>
+#include <QFutureInterface>
#include <QStringList>
#include <QTextCodec>
#include <QVariant>
@@ -81,12 +81,14 @@ class VcsCommandDecorator : public QObject
{
public:
VcsCommandDecorator(ShellCommand *command);
+ ~VcsCommandDecorator();
private:
void addTask(const QFuture<void> &future);
void postRunCommand(const FilePath &workingDirectory);
ShellCommand *m_command;
+ QFutureInterface<void> 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<void> &future)
{
@@ -133,18 +141,7 @@ void VcsCommandDecorator::addTask(const QFuture<void> &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<void>();
- auto watcher = new QFutureWatcher<void>();
- 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);