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 fab4dd068e
  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 <marco.bubke@qt.io>
This commit is contained in:
Nikolai Kosjar
2017-06-06 13:29:51 +02:00
parent 600dd3a585
commit c801965b58

View File

@@ -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<IAssistProposalModel> proposalCandidateModel(newProposal->model());
QScopedPointer<IAssistProposal> 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);