From f950d9632482ce71f263da7d7ae7c4d727a0ae6a Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Mon, 15 Nov 2021 10:04:44 -0800 Subject: [PATCH] Prevent dereferencing frame on exit Processing a menu event for quitting results in the frame being destroyed. This crashes the program when it tries to access the newly freed frame to check for autosave data. We bind the closing flag into the base program which will be the last item freed on exit to ensure we can correctly check for data loss Fixes https://gitlab.com/kicad/code/kicad/issues/8638 --- common/eda_base_frame.cpp | 3 +++ common/pgm_base.cpp | 1 + include/pgm_base.h | 2 ++ kicad/kicad_manager_frame.cpp | 2 ++ 4 files changed, 8 insertions(+) diff --git a/common/eda_base_frame.cpp b/common/eda_base_frame.cpp index 7782ed2fca..2572cbdbfd 100644 --- a/common/eda_base_frame.cpp +++ b/common/eda_base_frame.cpp @@ -273,6 +273,9 @@ bool EDA_BASE_FRAME::ProcessEvent( wxEvent& aEvent ) if( !wxFrame::ProcessEvent( aEvent ) ) return false; + if( Pgm().m_Quitting ) + return true; + if( !m_isClosing && m_hasAutoSave && IsShown() && IsActive() && m_autoSaveState != isAutoSaveRequired() && m_autoSaveInterval > 0 ) diff --git a/common/pgm_base.cpp b/common/pgm_base.cpp index 556918ae13..d9ddaa3991 100644 --- a/common/pgm_base.cpp +++ b/common/pgm_base.cpp @@ -108,6 +108,7 @@ PGM_BASE::PGM_BASE() { m_locale = nullptr; m_Printing = false; + m_Quitting = false; m_ModalDialogCount = 0; setLanguageId( wxLANGUAGE_DEFAULT ); diff --git a/include/pgm_base.h b/include/pgm_base.h index c78d0d159c..72ab349391 100644 --- a/include/pgm_base.h +++ b/include/pgm_base.h @@ -292,6 +292,8 @@ public: int m_ModalDialogCount; + bool m_Quitting; + protected: /// Loads internal settings from COMMON_SETTINGS void loadCommonSettings(); diff --git a/kicad/kicad_manager_frame.cpp b/kicad/kicad_manager_frame.cpp index 39e1da7b4c..01ab78590b 100644 --- a/kicad/kicad_manager_frame.cpp +++ b/kicad/kicad_manager_frame.cpp @@ -435,6 +435,8 @@ bool KICAD_MANAGER_FRAME::CloseProject( bool aSave ) m_leftWin->EmptyTreePrj(); + Pgm().m_Quitting = true; + return true; }