From 1c052378203a5dca88d6c0f69cd99731d2a86695 Mon Sep 17 00:00:00 2001 From: David Schulz Date: Thu, 22 Sep 2022 09:27:10 +0200 Subject: [PATCH] LanguageClient: prevent accessing freed data on shutdown Change-Id: I0d6e7abd653acb2ab7409a9cd5e58a2df3b1f259 Reviewed-by: Marcus Tillmanns Reviewed-by: Reviewed-by: Christian Stenger --- src/plugins/languageclient/client.cpp | 18 +++++++++++------- .../languageclient/languageclientmanager.cpp | 5 +++++ .../languageclient/languageclientmanager.h | 1 + 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/plugins/languageclient/client.cpp b/src/plugins/languageclient/client.cpp index 6f46c8f38e9..4d6aa06ea50 100644 --- a/src/plugins/languageclient/client.cpp +++ b/src/plugins/languageclient/client.cpp @@ -190,19 +190,23 @@ public: // temporary container needed since m_resetAssistProvider is changed in resetAssistProviders for (TextDocument *document : m_resetAssistProvider.keys()) resetAssistProviders(document); - const QList &editors = Core::DocumentModel::editorsForOpenedDocuments(); - for (Core::IEditor *editor : editors) { - if (auto textEditor = qobject_cast(editor)) { - TextEditorWidget *widget = textEditor->editorWidget(); - widget->setRefactorMarkers(RefactorMarker::filterOutType(widget->refactorMarkers(), m_id)); - widget->removeHoverHandler(&m_hoverHandler); + if (!LanguageClientManager::isShuttingDown()) { + // prevent accessing deleted editors on Creator shutdown + const QList &editors = Core::DocumentModel::editorsForOpenedDocuments(); + for (Core::IEditor *editor : editors) { + if (auto textEditor = qobject_cast(editor)) { + TextEditorWidget *widget = textEditor->editorWidget(); + widget->setRefactorMarkers( + RefactorMarker::filterOutType(widget->refactorMarkers(), m_id)); + widget->removeHoverHandler(&m_hoverHandler); + } } + updateEditorToolBar(m_openedDocument.keys()); } for (IAssistProcessor *processor : qAsConst(m_runningAssistProcessors)) processor->setAsyncProposalAvailable(nullptr); qDeleteAll(m_documentHighlightsTimer); m_documentHighlightsTimer.clear(); - updateEditorToolBar(m_openedDocument.keys()); // do not handle messages while shutting down disconnect(m_clientInterface, &InterfaceController::messageReceived, q, &Client::handleMessage); diff --git a/src/plugins/languageclient/languageclientmanager.cpp b/src/plugins/languageclient/languageclientmanager.cpp index e05294684eb..4edd8c03f77 100644 --- a/src/plugins/languageclient/languageclientmanager.cpp +++ b/src/plugins/languageclient/languageclientmanager.cpp @@ -232,6 +232,11 @@ void LanguageClientManager::shutdown() }); } +bool LanguageClientManager::isShuttingDown() +{ + return managerInstance->m_shuttingDown; +} + LanguageClientManager *LanguageClientManager::instance() { return managerInstance; diff --git a/src/plugins/languageclient/languageclientmanager.h b/src/plugins/languageclient/languageclientmanager.h index 7678b1467da..9e3aa0b30c1 100644 --- a/src/plugins/languageclient/languageclientmanager.h +++ b/src/plugins/languageclient/languageclientmanager.h @@ -50,6 +50,7 @@ public: static void deleteClient(Client *client); static void shutdown(); + static bool isShuttingDown(); static LanguageClientManager *instance();