From 8958ad22cdde4be651b7da5bd0b292c103d09dc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=A1clav=20Slav=C3=ADk?= Date: Fri, 15 Nov 2013 18:25:29 +0000 Subject: [PATCH] Don't crash in wxWindowMac::OSXSimulateFocusEvents(). The code didn't properly account for the possibility of wxEVT_KILL_FOCUS handler deleting the focused window (as happens e.g. in wxListCtrl inline edit controls). E.g. rapidly clicking wxEditableListBox buttons could trigger a crash here when sending wxEVT_SET_FOCUS to an already-deleted window. Use wxWeakRef<> to check if the window is still alive. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@75199 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/osx/window_osx.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/osx/window_osx.cpp b/src/osx/window_osx.cpp index 3d4eb703c1..0f8f921aae 100644 --- a/src/osx/window_osx.cpp +++ b/src/osx/window_osx.cpp @@ -39,6 +39,7 @@ #include "wx/tooltip.h" #include "wx/spinctrl.h" #include "wx/geometry.h" +#include "wx/weakref.h" #if wxUSE_LISTCTRL #include "wx/listctrl.h" @@ -610,7 +611,7 @@ void wxWindowMac::SetFocus() void wxWindowMac::OSXSimulateFocusEvents() { - wxWindow* former = FindFocus() ; + wxWeakRef former = FindFocus() ; if ( former != NULL && former != this ) { { @@ -620,6 +621,9 @@ void wxWindowMac::OSXSimulateFocusEvents() former->HandleWindowEvent(event) ; } + // 'former' could have been destroyed by a wxEVT_KILL_FOCUS handler, + // so we must test it for non-NULL again + if ( former ) { wxFocusEvent event(wxEVT_SET_FOCUS, former->GetId()); event.SetEventObject(former);