Commit d870bab9 authored by Nikolai Kosjar's avatar Nikolai Kosjar

CppEditor: Cancel runner in ~CppUseSelectionsUpdater

...otherwise an already destructed QTextDocument might be accessed in
the ClangCodeModel::Internal::IpcReceiver::references.

Task-number: QTCREATORBUG-18459
Change-Id: I1868b2fd3a64341794f83eea6c4eeb7c2c1af812
Reviewed-by: Orgad Shaneh's avatarOrgad Shaneh <orgads@gmail.com>
Reviewed-by: David Schulz's avatarDavid Schulz <david.schulz@qt.io>
parent 22829c19
......@@ -248,9 +248,9 @@ void IpcReceiver::references(const ReferencesMessage &message)
QTC_CHECK(futureInterface != QFutureInterface<CppTools::CursorInfo>());
if (futureInterface.isCanceled())
return; // A new request was issued making this one outdated.
return; // Editor document closed or a new request was issued making this result outdated.
QTC_CHECK(entry.textDocument);
QTC_ASSERT(entry.textDocument, return);
futureInterface.reportResult(toCursorInfo(*entry.textDocument, message));
futureInterface.reportFinished();
}
......
......@@ -35,6 +35,7 @@
#include <QFuture>
#include <QObject>
#include <QPointer>
#include <QSharedPointer>
#include <QTextDocument>
#include <QVector>
......@@ -102,7 +103,7 @@ private:
: futureInterface(futureInterface)
, textDocument(textDocument) {}
QFutureInterface<CppTools::CursorInfo> futureInterface;
QTextDocument *textDocument = nullptr;
QPointer<QTextDocument> textDocument;
};
QHash<quint64, ReferencesEntry> m_referencesTable;
};
......
......@@ -49,6 +49,12 @@ CppUseSelectionsUpdater::CppUseSelectionsUpdater(TextEditor::TextEditorWidget *e
connect(&m_timer, &QTimer::timeout, this, [this]() { update(); });
}
CppUseSelectionsUpdater::~CppUseSelectionsUpdater()
{
if (m_runnerWatcher)
m_runnerWatcher->cancel();
}
void CppUseSelectionsUpdater::scheduleUpdate()
{
m_timer.start();
......
......@@ -44,6 +44,7 @@ class CppUseSelectionsUpdater : public QObject
public:
explicit CppUseSelectionsUpdater(TextEditor::TextEditorWidget *editorWidget);
~CppUseSelectionsUpdater();
void scheduleUpdate();
void abortSchedule();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment