aboutsummaryrefslogtreecommitdiff
path: root/src/net.cpp
diff options
context:
space:
mode:
authorPatrick Strateman <patrick.strateman@gmail.com>2015-08-25 16:30:02 -0700
committerPatrick Strateman <patrick.strateman@gmail.com>2015-08-25 16:30:02 -0700
commitfed30940ef22f242b9dada2dc4f7c5348faf8922 (patch)
treec397e6d31f3ab7dc4b723bb4cc9dc6fd6f7512ea /src/net.cpp
parent69ee1aab00b9189865dfca6fb5c33c61a3c3ea67 (diff)
Acquire cs_vNodes before changing refrence counts
Diffstat (limited to 'src/net.cpp')
-rw-r--r--src/net.cpp14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/net.cpp b/src/net.cpp
index cb5a24f0a4..e1b0e83e99 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -777,8 +777,15 @@ static list<CNode*> vNodesDisconnected;
class CNodeRef {
public:
- CNodeRef(CNode *pnode) : _pnode(pnode) {_pnode->AddRef();}
- ~CNodeRef() {_pnode->Release();}
+ CNodeRef(CNode *pnode) : _pnode(pnode) {
+ LOCK(cs_vNodes);
+ _pnode->AddRef();
+ }
+
+ ~CNodeRef() {
+ LOCK(cs_vNodes);
+ _pnode->Release();
+ }
CNode& operator *() const {return *_pnode;};
CNode* operator ->() const {return _pnode;};
@@ -786,6 +793,8 @@ public:
CNodeRef& operator =(const CNodeRef& other)
{
if (this != &other) {
+ LOCK(cs_vNodes);
+
_pnode->Release();
_pnode = other._pnode;
_pnode->AddRef();
@@ -796,6 +805,7 @@ public:
CNodeRef(const CNodeRef& other):
_pnode(other._pnode)
{
+ LOCK(cs_vNodes);
_pnode->AddRef();
}
private: