ClangTools: Fix crash in document tool runner

Prevent removing refactor markers from already destroyed widgets.

Fixes: QTCREATORBUG-24982
Change-Id: Icf8950f8f8407fa8733a1ef30d05abb4a2b44dd4
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
David Schulz
2020-11-25 14:54:19 +01:00
parent 3680d6aa5c
commit b40dcf6d29
2 changed files with 14 additions and 7 deletions

View File

@@ -105,15 +105,21 @@ Diagnostics DocumentClangToolRunner::diagnosticsAtLine(int lineNumber) const
return diagnostics;
}
static void removeClangToolRefactorMarkers(TextEditor::TextEditorWidget *editor)
{
if (!editor)
return;
editor->setRefactorMarkers(
TextEditor::RefactorMarker::filterOutType(editor->refactorMarkers(),
Constants::CLANG_TOOL_FIXIT_AVAILABLE_MARKER_ID));
}
void DocumentClangToolRunner::scheduleRun()
{
for (DiagnosticMark *mark : m_marks)
mark->disable();
for (TextEditor::TextEditorWidget *editor : m_editorsWithMarkers) {
editor->setRefactorMarkers(
TextEditor::RefactorMarker::filterOutType(editor->refactorMarkers(),
Constants::CLANG_TOOL_FIXIT_AVAILABLE_MARKER_ID));
}
for (TextEditor::TextEditorWidget *editor : m_editorsWithMarkers)
removeClangToolRefactorMarkers(editor);
m_runTimer.start();
}
@@ -325,7 +331,8 @@ void DocumentClangToolRunner::onSuccess()
for (auto editor : TextEditor::BaseTextEditor::textEditorsForDocument(doc)) {
if (TextEditor::TextEditorWidget *widget = editor->editorWidget()) {
widget->setRefactorMarkers(markers + widget->refactorMarkers());
m_editorsWithMarkers << widget;
if (!m_editorsWithMarkers.contains(widget))
m_editorsWithMarkers << widget;
}
}

View File

@@ -83,7 +83,7 @@ private:
QList<DiagnosticMark *> m_marks;
FileInfo m_fileInfo;
QMetaObject::Connection m_projectSettingsUpdate;
QSet<TextEditor::TextEditorWidget *> m_editorsWithMarkers;
QList<QPointer<TextEditor::TextEditorWidget>> m_editorsWithMarkers;
SuppressedDiagnosticsList m_suppressed;
Utils::FilePath m_lastProjectDirectory;
};