Close socket when listening fails.

This commit is contained in:
Bartosz Taudul 2020-04-13 21:40:35 +02:00
parent 5437976e65
commit 1f3dc927c0

View File

@ -336,8 +336,8 @@ bool ListenSocket::Listen( int port, int backlog )
int val = 1; int val = 1;
setsockopt( m_sock, SOL_SOCKET, SO_REUSEADDR, &val, sizeof( val ) ); setsockopt( m_sock, SOL_SOCKET, SO_REUSEADDR, &val, sizeof( val ) );
#endif #endif
if( bind( m_sock, res->ai_addr, res->ai_addrlen ) == -1 ) { freeaddrinfo( res ); return false; } if( bind( m_sock, res->ai_addr, res->ai_addrlen ) == -1 ) { freeaddrinfo( res ); Close(); return false; }
if( listen( m_sock, backlog ) == -1 ) { freeaddrinfo( res ); return false; } if( listen( m_sock, backlog ) == -1 ) { freeaddrinfo( res ); Close(); return false; }
freeaddrinfo( res ); freeaddrinfo( res );
return true; return true;
} }