diff options
author | Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> | 2021-04-12 14:54:58 +0300 |
---|---|---|
committer | Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> | 2021-04-22 17:28:39 +0300 |
commit | a3d090d1103cd6c25daf07afdf4e65febca6d3f7 (patch) | |
tree | d56437fabbfdda126e24aa011dda36710d476250 /src/net.cpp | |
parent | f0b457212f9876a8c7e4d680178b49b555b488e2 (diff) |
net: Restrict period when cs_vNodes mutex is locked
Diffstat (limited to 'src/net.cpp')
-rw-r--r-- | src/net.cpp | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/net.cpp b/src/net.cpp index ae38acdc3c..65f8b8baec 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -2636,8 +2636,9 @@ void CConnman::StopNodes() } // Close sockets - LOCK(cs_vNodes); - for (CNode* pnode : vNodes) + std::vector<CNode*> nodes; + WITH_LOCK(cs_vNodes, nodes.swap(vNodes)); + for (CNode* pnode : nodes) pnode->CloseSocketDisconnect(); for (ListenSocket& hListenSocket : vhListenSocket) if (hListenSocket.socket != INVALID_SOCKET) @@ -2645,13 +2646,12 @@ void CConnman::StopNodes() LogPrintf("CloseSocket(hListenSocket) failed with error %s\n", NetworkErrorString(WSAGetLastError())); // clean up some globals (to help leak detection) - for (CNode* pnode : vNodes) { + for (CNode* pnode : nodes) { DeleteNode(pnode); } for (CNode* pnode : vNodesDisconnected) { DeleteNode(pnode); } - vNodes.clear(); vNodesDisconnected.clear(); vhListenSocket.clear(); semOutbound.reset(); |