From 96dbd381cf0ded169406bab3b1ba911a13d563c5 Mon Sep 17 00:00:00 2001 From: Cory Fields Date: Thu, 1 Feb 2018 10:29:15 -0500 Subject: [PATCH] net: initialize socket to avoid closing random fd's --- src/net.cpp | 2 +- src/netbase.cpp | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/net.cpp b/src/net.cpp index 8111390749c66..f407add091d60 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -410,7 +410,7 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo // Connect bool connected = false; - SOCKET hSocket; + SOCKET hSocket = INVALID_SOCKET; proxyType proxy; if (addrConnect.IsValid()) { bool proxyConnectionFailed = false; diff --git a/src/netbase.cpp b/src/netbase.cpp index 276b2f4dc2582..d51277c4950d4 100644 --- a/src/netbase.cpp +++ b/src/netbase.cpp @@ -682,6 +682,9 @@ bool CloseSocket(SOCKET& hSocket) #else int ret = close(hSocket); #endif + if (ret) { + LogPrintf("Socket close failed: %d. Error: %s\n", hSocket, NetworkErrorString(WSAGetLastError())); + } hSocket = INVALID_SOCKET; return ret != SOCKET_ERROR; }