diff options
author | Jarek Kobus <jaroslaw.kobus@qt.io> | 2021-11-01 13:18:43 +0100 |
---|---|---|
committer | Jarek Kobus <jaroslaw.kobus@qt.io> | 2021-11-01 15:19:15 +0000 |
commit | 6e8dcbcfd23414d0d6d9be659ce5a7c6d2de049a (patch) | |
tree | 51673e5c00ecb67fe7a8b98d6bcae61989310194 | |
parent | 38af447ee061932a31b654efd4cba9c713993c4a (diff) |
Fix a crash when modifying pro fileqds/v2.2.2
In some unlikely case it may happen that between finished() signal
is emitted by a watcher and when the queued handler is being called,
someone could have called CppProjectUpdater::cancel() and delete
the watcher immediately. In this case the handler could operate
on deleted watcher instance.
Add a QPointer in order to guard the watcher inside the queued
handler.
Amends: e3b639047f6a4a9c042987062bafdbf1726267cb
Fixes: QTCREATORBUG-26507
Change-Id: Idb4a953e9017ce672adc64becb3061bd80c8c378
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
-rw-r--r-- | src/plugins/cpptools/cppprojectupdater.cpp | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/plugins/cpptools/cppprojectupdater.cpp b/src/plugins/cpptools/cppprojectupdater.cpp index f34628af51..61d9443c98 100644 --- a/src/plugins/cpptools/cppprojectupdater.cpp +++ b/src/plugins/cpptools/cppprojectupdater.cpp @@ -93,11 +93,16 @@ void CppProjectUpdater::update(const ProjectUpdateInfo &projectUpdateInfo, // extra compilers for (QPointer<ExtraCompiler> compiler : qAsConst(m_extraCompilers)) { if (compiler->isDirty()) { - auto watcher = new QFutureWatcher<void>; + QPointer<QFutureWatcher<void>> watcher = new QFutureWatcher<void>; // queued connection to delay after the extra compiler updated its result contents, // which is also done in the main thread when compiler->run() finished connect(watcher, &QFutureWatcherBase::finished, this, [this, watcher] { + // In very unlikely case the CppProjectUpdater::cancel() could have been + // invoked after posting the finished() signal and before this handler + // gets called. In this case the watcher is already deleted. + if (!watcher) + return; m_projectUpdateFutureInterface->setProgressValue( m_projectUpdateFutureInterface->progressValue() + 1); m_extraCompilersFutureWatchers.remove(watcher); |