Browse Source

Acquire cs_vNodes before changing refrence counts

0.13
Patrick Strateman 9 years ago
parent
commit
fed30940ef
  1. 14
      src/net.cpp

14
src/net.cpp

@ -777,8 +777,15 @@ static list<CNode*> vNodesDisconnected;
class CNodeRef { class CNodeRef {
public: public:
CNodeRef(CNode *pnode) : _pnode(pnode) {_pnode->AddRef();} CNodeRef(CNode *pnode) : _pnode(pnode) {
~CNodeRef() {_pnode->Release();} LOCK(cs_vNodes);
_pnode->AddRef();
}
~CNodeRef() {
LOCK(cs_vNodes);
_pnode->Release();
}
CNode& operator *() const {return *_pnode;}; CNode& operator *() const {return *_pnode;};
CNode* operator ->() const {return _pnode;}; CNode* operator ->() const {return _pnode;};
@ -786,6 +793,8 @@ public:
CNodeRef& operator =(const CNodeRef& other) CNodeRef& operator =(const CNodeRef& other)
{ {
if (this != &other) { if (this != &other) {
LOCK(cs_vNodes);
_pnode->Release(); _pnode->Release();
_pnode = other._pnode; _pnode = other._pnode;
_pnode->AddRef(); _pnode->AddRef();
@ -796,6 +805,7 @@ public:
CNodeRef(const CNodeRef& other): CNodeRef(const CNodeRef& other):
_pnode(other._pnode) _pnode(other._pnode)
{ {
LOCK(cs_vNodes);
_pnode->AddRef(); _pnode->AddRef();
} }
private: private:

Loading…
Cancel
Save