aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJarek Kobus <jaroslaw.kobus@qt.io>2022-01-17 10:36:59 +0100
committerJarek Kobus <jaroslaw.kobus@qt.io>2022-01-17 10:31:59 +0000
commite1f45507c5f689a346ec67ebb4ec45f6fc886fbe (patch)
tree94eff7f2b3c60583b4278be531c641da2bfde159
parentf9c21253c0cecf788c45f39f5adcff6fc5ce17ec (diff)
LanguageClient: fix possible crash on shutdown
Iterate on a copy of managerInstance->m_clients when calling shutdownClient() or deleteClient(), since both methods may potentially modify m_clients list and thus invalidate outer iterators. Surprisingly, this patch also fixes the leak of RunControl and RunWorker instances on shutdown. Task-number: QTCREATORBUG-25709 Fixes: QTCREATORBUG-26847 Change-Id: Ib34d913a6ae0b235631d3d619bddaf4e08b4aec2 Reviewed-by: David Schulz <david.schulz@qt.io>
-rw-r--r--src/plugins/languageclient/languageclientmanager.cpp8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/plugins/languageclient/languageclientmanager.cpp b/src/plugins/languageclient/languageclientmanager.cpp
index 0e5a80013b..643e4f5cfc 100644
--- a/src/plugins/languageclient/languageclientmanager.cpp
+++ b/src/plugins/languageclient/languageclientmanager.cpp
@@ -253,10 +253,12 @@ void LanguageClientManager::shutdown()
return;
qCDebug(Log) << "shutdown manager";
managerInstance->m_shuttingDown = true;
- for (Client *client : qAsConst(managerInstance->m_clients))
+ const auto clients = managerInstance->clients();
+ for (Client *client : clients)
shutdownClient(client);
- QTimer::singleShot(3000, managerInstance, [](){
- for (Client *client : qAsConst(managerInstance->m_clients))
+ QTimer::singleShot(3000, managerInstance, [] {
+ const auto clients = managerInstance->clients();
+ for (Client *client : clients)
deleteClient(client);
emit managerInstance->shutdownFinished();
});