Cpp: Fix leaks in ClangCodeModel tests

Change-Id: I19d4dc445d82fd24361f1eb752d9f35ccadd3efb
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
Christian Kandeler
2020-06-19 10:17:21 +02:00
parent ae2cc246c3
commit b9413bcec7
2 changed files with 7 additions and 5 deletions

View File

@@ -41,6 +41,7 @@
#include <QCoreApplication>
#include <QElapsedTimer>
#include <QScopedPointer>
namespace ClangCodeModel {
namespace Internal {
@@ -69,7 +70,6 @@ public:
// Are there any immediate results?
if (TextEditor::IAssistProposal *proposal = processor->perform(assistInterface)) {
delete processor;
proposalModel = proposal->model();
delete proposal;
QTC_ASSERT(proposalModel, return GotInvalidResults);
@@ -80,8 +80,10 @@ public:
QElapsedTimer timer;
timer.start();
while (!gotResults) {
if (timer.elapsed() >= timeoutInMs)
if (timer.elapsed() >= timeoutInMs) {
processor->cancel();
return Timeout;
}
QCoreApplication::processEvents();
}
@@ -124,11 +126,11 @@ TextEditor::ProposalModelPtr completionResults(TextEditor::BaseTextEditor *textE
QTC_ASSERT(assistProvider->runType() == IAssistProvider::Asynchronous,
return TextEditor::ProposalModelPtr());
IAssistProcessor *processor = assistProvider->createProcessor();
QScopedPointer<IAssistProcessor> processor(assistProvider->createProcessor());
QTC_ASSERT(processor, return TextEditor::ProposalModelPtr());
WaitForAsyncCompletions waitForCompletions;
const WaitForAsyncCompletions::WaitResult result = waitForCompletions.wait(processor,
const WaitForAsyncCompletions::WaitResult result = waitForCompletions.wait(processor.data(),
assistInterface,
timeOutInMs);
QTC_ASSERT(result == WaitForAsyncCompletions::GotResults,

View File

@@ -975,7 +975,7 @@ void CppModelManager::watchForCanceledProjectIndexer(const QVector<QFuture<void>
if (future.isCanceled() || future.isFinished())
continue;
auto watcher = new QFutureWatcher<void>();
auto watcher = new QFutureWatcher<void>(this);
connect(watcher, &QFutureWatcher<void>::canceled, this, [this, project, watcher]() {
if (d->m_projectToIndexerCanceled.contains(project)) // Project not yet removed
d->m_projectToIndexerCanceled.insert(project, true);