From bfd2d02b3eee4d656ce8ea56c148342a337332c9 Mon Sep 17 00:00:00 2001 From: Kvaz1r Date: Sun, 29 Aug 2021 17:26:55 +0300 Subject: [PATCH] Fix crash in wxUniv when destroying MDI child frame Disassociate child frame menu bar from its parent before destroying it to avoid using a dangling pointer later, when destroying the parent. See https://github.com/wxWidgets/wxWidgets/pull/2505 Closes #19253. --- src/generic/mdig.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/generic/mdig.cpp b/src/generic/mdig.cpp index b56b4896b1..b3f27225a2 100644 --- a/src/generic/mdig.cpp +++ b/src/generic/mdig.cpp @@ -407,7 +407,15 @@ wxGenericMDIChildFrame::~wxGenericMDIChildFrame() parent->WXRemoveChild(this); #if wxUSE_MENUS - delete m_pMenuBar; + if ( m_pMenuBar ) + { + // calling WXRemoveChild() above broke the link between the menu bar + // and the parent, so we need to also remove it explicitly + if ( parent ) + parent->RemoveChild(m_pMenuBar); + + delete m_pMenuBar; + } #endif // wxUSE_MENUS }