From b2e0c2606ff200f0f42b6263e0ad0e82c4c160ac Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Sun, 26 May 2024 07:33:30 -0700 Subject: [PATCH] Avoid referencing parents after deletion We look at the parent when deleting EDA_ITEMs but when clearing the test sheet, we delete the sheet before the pin, causing a use-after-free. Avoid this by setting parents to null in this case Fixes https://gitlab.com/kicad/code/kicad/-/issues/17961 --- eeschema/dialogs/panel_eeschema_color_settings.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/eeschema/dialogs/panel_eeschema_color_settings.cpp b/eeschema/dialogs/panel_eeschema_color_settings.cpp index 5127e25594..71d1bdc1e1 100644 --- a/eeschema/dialogs/panel_eeschema_color_settings.cpp +++ b/eeschema/dialogs/panel_eeschema_color_settings.cpp @@ -106,7 +106,11 @@ PANEL_EESCHEMA_COLOR_SETTINGS::~PANEL_EESCHEMA_COLOR_SETTINGS() delete m_currentSettings; for( EDA_ITEM* item : m_previewItems ) + { + // Avoid referencing items after they are deleted (we don't control order) + item->SetParent( nullptr ); delete item; + } }