Clang: Fix memory leak on completion II

...for the following case:

  void fun1();
  void fun2();

  void g()
  {
      fu // Type 'n', wait for the widget, hit return to choose the item
  }

Once e.g. "fun1" is chosen, the completion is triggered again but the
processor (and as result the assist interface) is not freed.

The assumption was that for the AsynchronousWithThread case
IAssistProcessor::perform() would either return 0 (async completion was
started) or != 0 for an immediate proposal. It turns out there is a
third case: no proposal if the completion is not applicable, e.g.
choosing an item in the example above will retrigger completion, however
no completion makes sense for "fun1()<CURSOR>" for an idle editor.

Workaround the case with a getter/setter in IAssistProcessor. Proper
solution should (slightly?) rework the IAssistProcessor API.

Change-Id: I44dde8287998d54ded1ea07e7c39a5157cf62029
Reviewed-by: Erik Verbruggen <erik.verbruggen@theqtcompany.com>
This commit is contained in:
Nikolai Kosjar
2015-07-29 12:15:15 +02:00
parent 6bb2aa6ba1
commit a1da7182f9
3 changed files with 9 additions and 1 deletions

View File

@@ -226,8 +226,10 @@ IAssistProposal *ClangCompletionAssistProcessor::perform(const AssistInterface *
{
m_interface.reset(static_cast<const ClangCompletionAssistInterface *>(interface));
if (interface->reason() != ExplicitlyInvoked && !accepts())
if (interface->reason() != ExplicitlyInvoked && !accepts()) {
setPerformWasApplicable(false);
return 0;
}
return startCompletionHelper(); // == 0 if results are calculated asynchronously
}