From c639aa82d40b136626571857d31825ab00c74796 Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Mon, 17 Feb 2025 14:24:13 +0100 Subject: [PATCH] EditorManager: Guard against potential crash At this point `entry` should not be nullptr, since the editors passed to closeEditor should be ones that are managed by EditorManager/ DocumentModel. But there could be misusage of the EditorManager API, or some other corruption of the managed data in DocumentModel, so be defensive. Amends 119a0920c119e1bf631b16babab72b5c71740495 Task-number: QTCREATORBUG-32484 Change-Id: I3f173d1fe7c3533d4f044fd23171c69ab65bb9d8 Reviewed-by: Mitch Curtis Reviewed-by: David Schulz --- src/plugins/coreplugin/editormanager/editormanager.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/plugins/coreplugin/editormanager/editormanager.cpp b/src/plugins/coreplugin/editormanager/editormanager.cpp index 8e95d7bcf08..cb882f9f000 100644 --- a/src/plugins/coreplugin/editormanager/editormanager.cpp +++ b/src/plugins/coreplugin/editormanager/editormanager.cpp @@ -1618,7 +1618,8 @@ bool EditorManagerPrivate::closeEditors(const QList &editors, CloseFla emit m_instance->editorAboutToClose(editor); const DocumentModel::Entry *entry = DocumentModel::entryForDocument(editor->document()); // If the file is pinned, closing it should remove the editor but keep it in Open Documents. - const bool removeSuspendedEntry = !entry->pinned && flag != CloseFlag::Suspend; + const bool isPinned = QTC_GUARD(entry) && entry->pinned; + const bool removeSuspendedEntry = !isPinned && flag != CloseFlag::Suspend; removeEditor(editor, removeSuspendedEntry); if (EditorView *view = viewForEditor(editor)) { editorsPerView.insert(view, editor);