From c801965b580bc2e262d31b38a5a3ee413162afab Mon Sep 17 00:00:00 2001 From: Nikolai Kosjar Date: Tue, 6 Jun 2017 13:29:51 +0200 Subject: [PATCH] CodeAssist: Fix leaking proposal model The model is not owned by the proposal. For corner cases, we leaked here already for ages. Starting with commit fab4dd068ed51f612e7beaf0985bcbe4411d2f01 CodeAssist: Fix auto completion if function signature is shown leaks happened also for a hot path: code completion results that does not match any so far typed prefix. Due to auto completion turned on, this triggers frequently when typing text. Task-number: QTCREATORBUG-17752 Task-number: QTCREATORBUG-18326 Change-Id: I9df177723b31cf3df36e73ef1e7920d9aa5e16e5 Reviewed-by: Marco Bubke --- src/plugins/texteditor/codeassist/codeassistant.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/plugins/texteditor/codeassist/codeassistant.cpp b/src/plugins/texteditor/codeassist/codeassistant.cpp index ab3b9907a9e..d5e184f2e68 100644 --- a/src/plugins/texteditor/codeassist/codeassistant.cpp +++ b/src/plugins/texteditor/codeassist/codeassistant.cpp @@ -285,6 +285,8 @@ void CodeAssistantPrivate::displayProposal(IAssistProposal *newProposal, AssistR if (!newProposal) return; + // TODO: The proposal should own the model until someone takes it explicitly away. + QScopedPointer proposalCandidateModel(newProposal->model()); QScopedPointer proposalCandidate(newProposal); bool destroyCurrentContext = false; @@ -336,7 +338,7 @@ void CodeAssistantPrivate::displayProposal(IAssistProposal *newProposal, AssistR m_proposalWidget->setReason(reason); m_proposalWidget->setKind(m_assistKind); m_proposalWidget->setUnderlyingWidget(m_editorWidget); - m_proposalWidget->setModel(m_proposal->model()); + m_proposalWidget->setModel(proposalCandidateModel.take()); m_proposalWidget->setDisplayRect(m_editorWidget->cursorRect(basePosition)); m_proposalWidget->setIsSynchronized(!m_receivedContentWhileWaiting); m_proposalWidget->showProposal(prefix);