diff --git a/docs/changes.txt b/docs/changes.txt index 035a2646e4..4b055568a9 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -112,6 +112,10 @@ All (Unix): - Fixed shared libraries do not depend on GStreamer when built with --enable-media; only wxMedia library depends on it now. +wxMSW: + +- Fix rare bug with messages delivered to wrong wxSocket (Tim Kosse) + wxGTK: diff --git a/src/msw/gsockmsw.cpp b/src/msw/gsockmsw.cpp index 12ae969e4c..3011673f06 100644 --- a/src/msw/gsockmsw.cpp +++ b/src/msw/gsockmsw.cpp @@ -336,7 +336,19 @@ void GSocketGUIFunctionsTableConcrete::Destroy_Socket(GSocket *socket) /* Remove the socket from the list */ EnterCriticalSection(&critical); if ( socket->IsOk() ) - socketList[(socket->m_msgnumber - WM_USER)] = NULL; + { + const int msgnum = socket->m_msgnumber; + + // we need to remove any pending messages for this socket to avoid having + // them sent to a new socket which could reuse the same message number as + // soon as we destroy this one + MSG msg; + while ( ::PeekMessage(&msg, hWin, msgnum, msgnum, PM_REMOVE) ) + ; + + socketList[msgnum - WM_USER] = NULL; + } + LeaveCriticalSection(&critical); }