From 3bfa5392facebaebe37be1a39cbb5ef4abbf2d52 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Wed, 1 Feb 2017 21:24:00 +0400 Subject: [PATCH] fix flag/ref order + cs_vNodes in ConnectNode (#1300) * fix flag/ref order * hold cs_vNodes in ConnectNode a little bit longer * fix --- src/net.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/net.cpp b/src/net.cpp index fa3fec7cc..f65729d7a 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -392,6 +392,7 @@ CNode* ConnectNode(CAddress addrConnect, const char *pszDest, bool fConnectToMas if (IsLocal(addrConnect) && !fConnectToMasternode) return NULL; + LOCK(cs_vNodes); // Look for an existing connection CNode* pnode = FindNode((CService)addrConnect); if (pnode) @@ -399,8 +400,8 @@ CNode* ConnectNode(CAddress addrConnect, const char *pszDest, bool fConnectToMas // we have existing connection to this node but it was not a connection to masternode, // change flag and add reference so that we can correctly clear it later if(fConnectToMasternode && !pnode->fMasternode) { - pnode->fMasternode = true; pnode->AddRef(); + pnode->fMasternode = true; } return pnode; } @@ -428,15 +429,13 @@ CNode* ConnectNode(CAddress addrConnect, const char *pszDest, bool fConnectToMas // Add node CNode* pnode = new CNode(hSocket, addrConnect, pszDest ? pszDest : "", false, true); - { - LOCK(cs_vNodes); - vNodes.push_back(pnode); - } + LOCK(cs_vNodes); + vNodes.push_back(pnode); pnode->nTimeConnected = GetTime(); if(fConnectToMasternode) { - pnode->fMasternode = true; pnode->AddRef(); + pnode->fMasternode = true; } return pnode;