From ebdfeb4c0aa70ea773389f4e4fb23eeae0f190af Mon Sep 17 00:00:00 2001 From: Alex Shvartzkop Date: Wed, 19 Jun 2024 00:49:53 +0300 Subject: [PATCH] Fix crash in wxSocketBase when the event handler has been destroyed. Fixes KICAD-37B Fixes https://gitlab.com/kicad/code/kicad/-/issues/18234 --- common/kiway_player.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/common/kiway_player.cpp b/common/kiway_player.cpp index a715d8d1d7..d18ac4c8a4 100644 --- a/common/kiway_player.cpp +++ b/common/kiway_player.cpp @@ -57,7 +57,6 @@ KIWAY_PLAYER::KIWAY_PLAYER( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrameType KIWAY_PLAYER::~KIWAY_PLAYER() throw() { - // socket server must be destructed before we complete // destructing the frame or else we could crash // as the socket server holds a reference to this frame @@ -69,6 +68,20 @@ KIWAY_PLAYER::~KIWAY_PLAYER() throw() delete m_socketServer; m_socketServer = nullptr; } + + // remove active sockets as well + for( wxSocketBase* socket : m_sockets ) + { + if( !socket ) + continue; + + // ensure any event handling stops + socket->Notify( false ); + + delete socket; + } + + m_sockets.clear(); }