Skip to content

Commit

Permalink
Backport of Bitcoin PR #21750
Browse files Browse the repository at this point in the history
Partial backport of Bitcoin PR #19347
  • Loading branch information
JackPiri committed Sep 20, 2023
1 parent 7d9788d commit 1ed962f
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1298,22 +1298,14 @@ void ThreadSocketHandler()
list<CNode*> vNodesDisconnectedCopy = connman->vNodesDisconnected;
BOOST_FOREACH(CNode* pnode, vNodesDisconnectedCopy)
{
// wait until threads are done using it
if (pnode->GetRefCount() <= 0)
// Destroy the object only after other threads have stopped using it
if (pnode->GetRefCount() == 0)
{
bool fDelete = false;
{
TRY_LOCK(pnode->cs_vSend, lockSend);
if (lockSend)
{
TRY_LOCK(pnode->cs_vRecvMsg, lockRecv);
if (lockRecv)
{
TRY_LOCK(pnode->cs_inventory, lockInv);
if (lockInv)
fDelete = true;
}
}
TRY_LOCK(pnode->cs_vRecvMsg, lockRecv);
if (lockRecv)
fDelete = true;
}
if (fDelete)
{
Expand Down

0 comments on commit 1ed962f

Please sign in to comment.