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 <eike.ziller@qt.io>
This commit is contained in:
David Schulz
2024-09-16 07:17:33 +02:00
parent 83f3e088f2
commit 7781e852e0

View File

@@ -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;
}