LanguageClient: fix race condition on client shutdown

If a document is closed between removing a closing client from the
tracked clients in the LanguageClientManager and the actual destruction
of that client we might derefernce an already desctructed document in
resetAssistProvider.

Connect the document closed signal in the client instead of the manager
so Client::closeDocument gets called even if it is not tracked in the
manager anymore.

Fixes: QTCREATORBUG-26534
Change-Id: I7187730600eeb1df54355065eb9cb703a605139e
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
David Schulz
2022-02-11 14:50:57 +01:00
parent 8dcb5097f5
commit 5b307634c3
3 changed files with 12 additions and 4 deletions

View File

@@ -542,11 +542,8 @@ void LanguageClientManager::documentOpened(Core::IDocument *document)
void LanguageClientManager::documentClosed(Core::IDocument *document)
{
if (auto textDocument = qobject_cast<TextEditor::TextDocument *>(document)) {
for (Client *client : qAsConst(m_clients))
client->closeDocument(textDocument);
if (auto textDocument = qobject_cast<TextEditor::TextDocument *>(document))
m_clientForDocument.remove(textDocument);
}
}
void LanguageClientManager::documentContentsSaved(Core::IDocument *document)