diff --git a/docs/changes.txt b/docs/changes.txt index 0f13127a54..a955d366ea 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -299,6 +299,10 @@ All (GUI): - Added wxWindow::GetNextSibling() and GetPrevSibling() +wxMSW: + +- Fix rare bug with messages delivered to wrong wxSocket (Tim Kosse) + 2.8.7 ----- diff --git a/src/msw/gsockmsw.cpp b/src/msw/gsockmsw.cpp index a1ada1918b..79969ac301 100644 --- a/src/msw/gsockmsw.cpp +++ b/src/msw/gsockmsw.cpp @@ -311,7 +311,19 @@ void GSocketMSWManager::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); }