Skip to content

Commit

Permalink
Acquire cs_vNodes before changing refrence counts
Browse files Browse the repository at this point in the history
  • Loading branch information
pstratem authored and Fuzzbawls committed Jun 23, 2020
1 parent 7aa827f commit 18af800
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -891,15 +891,24 @@ static std::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;};

CNodeRef& operator =(const CNodeRef& other)
{
if (this != &other) {
LOCK(cs_vNodes);

_pnode->Release();
_pnode = other._pnode;
_pnode->AddRef();
Expand All @@ -910,6 +919,7 @@ class CNodeRef {
CNodeRef(const CNodeRef& other):
_pnode(other._pnode)
{
LOCK(cs_vNodes);
_pnode->AddRef();
}
private:
Expand Down

0 comments on commit 18af800

Please sign in to comment.