diff options
author | Nikolai Kosjar <nikolai.kosjar@theqtcompany.com> | 2015-07-29 12:15:15 +0200 |
---|---|---|
committer | Nikolai Kosjar <nikolai.kosjar@theqtcompany.com> | 2015-07-29 12:18:39 +0000 |
commit | a1da7182f91a8d3a197f6356eafbba46e52cd2a3 (patch) | |
tree | 14b7e7d91a3007beeb35adf358f7eb0aae3f6953 /src/plugins/texteditor | |
parent | 6bb2aa6ba15519e1593d82d93ac818ff95e9d443 (diff) | |
download | qt-creator-a1da7182f91a8d3a197f6356eafbba46e52cd2a3.tar.gz |
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>
Diffstat (limited to 'src/plugins/texteditor')
-rw-r--r-- | src/plugins/texteditor/codeassist/codeassistant.cpp | 2 | ||||
-rw-r--r-- | src/plugins/texteditor/codeassist/iassistprocessor.h | 4 |
2 files changed, 6 insertions, 0 deletions
diff --git a/src/plugins/texteditor/codeassist/codeassistant.cpp b/src/plugins/texteditor/codeassist/codeassistant.cpp index 65a899a384..8b4c5600de 100644 --- a/src/plugins/texteditor/codeassist/codeassistant.cpp +++ b/src/plugins/texteditor/codeassist/codeassistant.cpp @@ -281,6 +281,8 @@ void CodeAssistantPrivate::requestProposal(AssistReason reason, if (IAssistProposal *newProposal = processor->perform(assistInterface)) { displayProposal(newProposal, reason); delete processor; + } else if (!processor->performWasApplicable()) { + delete processor; } // ...otherwise the async request was triggered diff --git a/src/plugins/texteditor/codeassist/iassistprocessor.h b/src/plugins/texteditor/codeassist/iassistprocessor.h index 0d4fd31e9d..3456434c86 100644 --- a/src/plugins/texteditor/codeassist/iassistprocessor.h +++ b/src/plugins/texteditor/codeassist/iassistprocessor.h @@ -56,8 +56,12 @@ public: using AsyncCompletionsAvailableHandler = std::function<void (IAssistProposal *proposal)>; void setAsyncCompletionAvailableHandler(const AsyncCompletionsAvailableHandler &finalizer); + bool performWasApplicable() { return m_performWasApplicable; } + void setPerformWasApplicable(bool applicable) { m_performWasApplicable = applicable; } + private: AsyncCompletionsAvailableHandler m_asyncCompletionsAvailableHandler; + bool m_performWasApplicable = true; }; } // TextEditor |