diff options
author | Matt Corallo <git@bluematt.me> | 2017-01-24 16:50:27 -0500 |
---|---|---|
committer | Matt Corallo <git@bluematt.me> | 2017-01-24 17:01:45 -0500 |
commit | 3c37dc40d39e1a1e56b6b0d3e660626a78656d4f (patch) | |
tree | 82ed28ec4782f4fd063a4462781dde83479ef744 | |
parent | 5be01906e59d484ec997b594e39bab528845bb78 (diff) |
Ensure cs_vNodes is held when using the return value from FindNode
-rw-r--r-- | src/net.cpp | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/src/net.cpp b/src/net.cpp index 4e296a3114..7489b3f32b 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -369,15 +369,13 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo // In that case, drop the connection that was just created, and return the existing CNode instead. // Also store the name we used to connect in that CNode, so that future FindNode() calls to that // name catch this early. + LOCK(cs_vNodes); CNode* pnode = FindNode((CService)addrConnect); if (pnode) { pnode->AddRef(); - { - LOCK(cs_vNodes); - if (pnode->addrName.empty()) { - pnode->addrName = std::string(pszDest); - } + if (pnode->addrName.empty()) { + pnode->addrName = std::string(pszDest); } CloseSocket(hSocket); return pnode; @@ -2373,6 +2371,7 @@ void CConnman::GetNodeStats(std::vector<CNodeStats>& vstats) bool CConnman::DisconnectNode(const std::string& strNode) { + LOCK(cs_vNodes); if (CNode* pnode = FindNode(strNode)) { pnode->fDisconnect = true; return true; |