Skip to content

Commit

Permalink
Protect vNodes/vNodesDisconnected in CConnman::Stop()
Browse files Browse the repository at this point in the history
  • Loading branch information
UdjinM6 committed Apr 17, 2020
1 parent 2f1b3a3 commit 3ae02dd
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2897,23 +2897,30 @@ void CConnman::Stop()
fAddressesInitialized = false;
}

// Close sockets
for (CNode* pnode : vNodes)
pnode->CloseSocketDisconnect();
for (ListenSocket& hListenSocket : vhListenSocket)
if (hListenSocket.socket != INVALID_SOCKET)
if (!CloseSocket(hListenSocket.socket))
LogPrintf("CloseSocket(hListenSocket) failed with error %s\n", NetworkErrorString(WSAGetLastError()));

// clean up some globals (to help leak detection)
for (CNode *pnode : vNodes) {
DeleteNode(pnode);
std::vector<CNode*> vNodesToDelete;
{
LOCK2(cs_vNodes, cs_vNodesDisconnected);
// Close sockets
for (CNode* pnode : vNodes)
pnode->CloseSocketDisconnect();
for (ListenSocket& hListenSocket : vhListenSocket)
if (hListenSocket.socket != INVALID_SOCKET)
if (!CloseSocket(hListenSocket.socket))
LogPrintf("CloseSocket(hListenSocket) failed with error %s\n", NetworkErrorString(WSAGetLastError()));

// clean up some globals (to help leak detection)
for (CNode *pnode : vNodes) {
vNodesToDelete.emplace_back(pnode);
}
for (CNode *pnode : vNodesDisconnected) {
vNodesToDelete.emplace_back(pnode);
}
vNodes.clear();
vNodesDisconnected.clear();
}
for (CNode *pnode : vNodesDisconnected) {
for (auto pnode : vNodesToDelete) {
DeleteNode(pnode);
}
vNodes.clear();
vNodesDisconnected.clear();
vhListenSocket.clear();
semOutbound.reset();
semAddnode.reset();
Expand Down

0 comments on commit 3ae02dd

Please sign in to comment.