From 9cd97e940b8fb4eadd6d42eaee79835b34d1804b Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Tue, 13 Jul 2021 12:33:32 +0200 Subject: [PATCH] EditorManager: Update current editor prior to deleting other editors Otherwise it may happen that destructor of an editor being deleted may trigger a call to EditorManager::currentEditor() before reaching the editor's QObject destructor. In this case the pointer to the editor (EditorManagerPrivate::m_currentEditor) isn't cleared yet by Qt and it may return the pointer to partially destructed object. Change-Id: I4f44dce8d680008148a73eb2a8ac13477d0fb825 Reviewed-by: Eike Ziller --- src/plugins/coreplugin/editormanager/editormanager.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/plugins/coreplugin/editormanager/editormanager.cpp b/src/plugins/coreplugin/editormanager/editormanager.cpp index 5213756975a..ce178bb2fbd 100644 --- a/src/plugins/coreplugin/editormanager/editormanager.cpp +++ b/src/plugins/coreplugin/editormanager/editormanager.cpp @@ -1751,9 +1751,6 @@ bool EditorManagerPrivate::closeEditors(const QList &editors, CloseFla emit m_instance->editorsClosed(Utils::toList(acceptedEditors)); - foreach (IEditor *editor, acceptedEditors) - delete editor; - if (focusView) { activateView(focusView); } else { @@ -1761,6 +1758,9 @@ bool EditorManagerPrivate::closeEditors(const QList &editors, CloseFla setCurrentEditor(currentView->currentEditor()); } + foreach (IEditor *editor, acceptedEditors) + delete editor; + if (!EditorManager::currentEditor()) { emit m_instance->currentEditorChanged(nullptr); updateActions();