From: Vadim Zeitlin Date: Fri, 20 Jul 2012 11:54:56 +0000 (+0000) Subject: Don't use delayed destruction for sockets in other threads. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/ee5cc6302e3bb8285304ad3a8e2aabb4fdcdeb36 Don't use delayed destruction for sockets in other threads. The delayed destruction mechanism is not MT-safe, so using it for wxSocket objects destroyed from threads other than main resulted in crashes. Luckily, it is not necessary to use it for such sockets anyhow as they don't risk receiving any events -- which are only dispatched in the main thread -- and so can be destroyed immediately. So do destroy them directly instead of just scheduling for later destruction when wxSocket::Destroy() is called. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72158 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/common/socket.cpp b/src/common/socket.cpp index 0d619a77c2..6f32e83791 100644 --- a/src/common/socket.cpp +++ b/src/common/socket.cpp @@ -887,8 +887,12 @@ bool wxSocketBase::Destroy() Notify(false); // Schedule this object for deletion instead of destroying it right now if - // possible as we may have other events pending for it - if ( wxTheApp ) + // it can have other events pending for it and we have a way to do it. + // + // Notice that sockets used in other threads won't have any events for them + // and we shouldn't use delayed destruction mechanism for them as it's not + // MT-safe. + if ( wxIsMainThread() && wxTheApp ) { wxTheApp->ScheduleForDestruction(this); }