From 7781e852e0131d8e64d83904db0c6cb54f0a584d Mon Sep 17 00:00:00 2001 From: David Schulz Date: Mon, 16 Sep 2024 07:17:33 +0200 Subject: [PATCH] TextEditor: Fix crash after request provider destruction If an assist provider gets destructed while a code assist request is running we need to cancel the running request and reset the provider. Otherwise we might try to cast the deleted provider in CodeAssistantPrivate::isDestroyEvent. Which is called whenever the texteditor is changed. Fixes: QTCREATORBUG-31563 Change-Id: Iaec36c6ca73ba5e6795c1c3847da8b30fd446ffc Reviewed-by: Eike Ziller --- src/plugins/texteditor/codeassist/codeassistant.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/plugins/texteditor/codeassist/codeassistant.cpp b/src/plugins/texteditor/codeassist/codeassistant.cpp index 0bdf34efaba..27f8f8fe259 100644 --- a/src/plugins/texteditor/codeassist/codeassistant.cpp +++ b/src/plugins/texteditor/codeassist/codeassistant.cpp @@ -183,6 +183,8 @@ void CodeAssistantPrivate::requestProposal(AssistReason reason, m_assistKind = kind; m_requestProvider = provider; + connect( + m_requestProvider, &QObject::destroyed, this, &CodeAssistantPrivate::cancelCurrentRequest); IAssistProcessor *processor = provider->createProcessor(assistInterface.get()); processor->setAsyncCompletionAvailableHandler([this, reason, processor]( IAssistProposal *newProposal) { @@ -367,6 +369,8 @@ void CodeAssistantPrivate::invalidateCurrentRequestData() { m_processor = nullptr; m_requestProvider = nullptr; + disconnect( + m_requestProvider, &QObject::destroyed, this, &CodeAssistantPrivate::cancelCurrentRequest); m_receivedContentWhileWaiting = false; }