Fix socket leak in Accept() in case of error.o
We leaked a socket descriptor if creating the accepted socket object failed. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@75952 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -38,6 +38,7 @@
|
||||
|
||||
#include "wx/apptrait.h"
|
||||
#include "wx/sckaddr.h"
|
||||
#include "wx/scopeguard.h"
|
||||
#include "wx/stopwatch.h"
|
||||
#include "wx/thread.h"
|
||||
#include "wx/evtloop.h"
|
||||
@@ -527,6 +528,8 @@ wxSocketImpl *wxSocketImpl::Accept(wxSocketBase& wxsocket)
|
||||
WX_SOCKLEN_T fromlen = sizeof(from);
|
||||
const wxSOCKET_T fd = accept(m_fd, &from.addr, &fromlen);
|
||||
|
||||
wxScopeGuard closeSocket = wxMakeGuard(close, fd);
|
||||
|
||||
// accepting is similar to reading in the sense that it resets "ready for
|
||||
// read" flag on the socket
|
||||
ReenableEvents(wxSOCKET_INPUT_FLAG);
|
||||
@@ -542,6 +545,8 @@ wxSocketImpl *wxSocketImpl::Accept(wxSocketBase& wxsocket)
|
||||
if ( !sock )
|
||||
return NULL;
|
||||
|
||||
// Ownership of the socket now passes to wxSocketImpl object.
|
||||
closeSocket.Dismiss();
|
||||
sock->m_fd = fd;
|
||||
sock->m_peer = wxSockAddressImpl(from.addr, fromlen);
|
||||
|
||||
|
Reference in New Issue
Block a user