From 1d844882edbb0c44d39ca5171b35c3939c74126b Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 27 Oct 2019 15:50:33 +0100 Subject: [PATCH] Avoid closing invalid socket after unsuccessful Accept() Calling wxSocket::Accept() may return an invalid socket, especially when non-blocking, so don't close it unconditionally. This avoids an assertion failure in MSVC CRT due to calling closesocket() with an invalid argument. --- src/common/socket.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/common/socket.cpp b/src/common/socket.cpp index eb971f952f..23276fb412 100644 --- a/src/common/socket.cpp +++ b/src/common/socket.cpp @@ -529,8 +529,6 @@ wxSocketImpl *wxSocketImpl::Accept(wxSocketBase& wxsocket) WX_SOCKLEN_T fromlen = sizeof(from); const wxSOCKET_T fd = accept(m_fd, &from.addr, &fromlen); - wxScopeGuard closeSocket = wxMakeGuard(wxCloseSocket, fd); - // accepting is similar to reading in the sense that it resets "ready for // read" flag on the socket ReenableEvents(wxSOCKET_INPUT_FLAG); @@ -538,6 +536,8 @@ wxSocketImpl *wxSocketImpl::Accept(wxSocketBase& wxsocket) if ( fd == INVALID_SOCKET ) return NULL; + wxScopeGuard closeSocket = wxMakeGuard(wxCloseSocket, fd); + wxSocketManager * const manager = wxSocketManager::Get(); if ( !manager ) return NULL;