Skip to content

Commit 3c37dc4

Browse files
committed
Ensure cs_vNodes is held when using the return value from FindNode
1 parent 5be0190 commit 3c37dc4

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/net.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -369,15 +369,13 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo
369369
// In that case, drop the connection that was just created, and return the existing CNode instead.
370370
// Also store the name we used to connect in that CNode, so that future FindNode() calls to that
371371
// name catch this early.
372+
LOCK(cs_vNodes);
372373
CNode* pnode = FindNode((CService)addrConnect);
373374
if (pnode)
374375
{
375376
pnode->AddRef();
376-
{
377-
LOCK(cs_vNodes);
378-
if (pnode->addrName.empty()) {
379-
pnode->addrName = std::string(pszDest);
380-
}
377+
if (pnode->addrName.empty()) {
378+
pnode->addrName = std::string(pszDest);
381379
}
382380
CloseSocket(hSocket);
383381
return pnode;
@@ -2373,6 +2371,7 @@ void CConnman::GetNodeStats(std::vector<CNodeStats>& vstats)
23732371

23742372
bool CConnman::DisconnectNode(const std::string& strNode)
23752373
{
2374+
LOCK(cs_vNodes);
23762375
if (CNode* pnode = FindNode(strNode)) {
23772376
pnode->fDisconnect = true;
23782377
return true;

0 commit comments

Comments
 (0)