Skip to content

Commit 96dbd38

Browse files
committed
net: initialize socket to avoid closing random fd's
1 parent 895fbd7 commit 96dbd38

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/net.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo
410410

411411
// Connect
412412
bool connected = false;
413-
SOCKET hSocket;
413+
SOCKET hSocket = INVALID_SOCKET;
414414
proxyType proxy;
415415
if (addrConnect.IsValid()) {
416416
bool proxyConnectionFailed = false;

src/netbase.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,9 @@ bool CloseSocket(SOCKET& hSocket)
682682
#else
683683
int ret = close(hSocket);
684684
#endif
685+
if (ret) {
686+
LogPrintf("Socket close failed: %d. Error: %s\n", hSocket, NetworkErrorString(WSAGetLastError()));
687+
}
685688
hSocket = INVALID_SOCKET;
686689
return ret != SOCKET_ERROR;
687690
}

0 commit comments

Comments
 (0)