From f15c021bb6fd68dd7be2c552f96ef365f57b99fe Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 20 Sep 2009 21:48:50 +0000 Subject: [PATCH] Fix possible deadlock in wxEvtHandler::ProcessPendingEvents(). Delete the event we just processed before re-locking the critical section as this may result in deadlocks if the (user-defined) event dtor does something non-trivial. Closes #10790. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@61982 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/event.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/common/event.cpp b/src/common/event.cpp index 25b9110c19..c4cb73abc7 100644 --- a/src/common/event.cpp +++ b/src/common/event.cpp @@ -1182,17 +1182,21 @@ void wxEvtHandler::ProcessPendingEvents() node; node = m_pendingEvents->GetFirst() ) { - wxEventPtr event(wx_static_cast(wxEvent *, node->GetData())); + { + wxEventPtr event(wx_static_cast(wxEvent *, node->GetData())); - // It's important we remove event from list before processing it. - // Else a nested event loop, for example from a modal dialog, might - // process the same event again. + // It's important we remove event from list before processing it. + // Else a nested event loop, for example from a modal dialog, might + // process the same event again. - m_pendingEvents->Erase(node); + m_pendingEvents->Erase(node); - wxLEAVE_CRIT_SECT( Lock() ); + wxLEAVE_CRIT_SECT( Lock() ); - ProcessEvent(*event); + ProcessEvent(*event); + } // delete the event at this block exit, before re-locking our + // critical section, to avoid deadlocks if the event dtor locks + // something else itself (see #10790) wxENTER_CRIT_SECT( Lock() );