Skip to content

Commit 84291d1

Browse files
committed
Merge #12326: net: initialize socket to avoid closing random fd's
96dbd38 net: initialize socket to avoid closing random fd's (Cory Fields) Pull request description: An excellent spot by @david60. Even if it isn't causing the fd issue we're looking for, this should be fixed. Tree-SHA512: 062a8f2cdd39d895213e1263dbd7b8391473ddaea2f93c82c211a9bb6ea6744d48a6c84c8ff804b16b865d14145492635c500a9fd138d0988fee5e4f719ebb91
2 parents 895fbd7 + 96dbd38 commit 84291d1

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)