Skip to content

Commit

Permalink
[net processing] Add comment about destructing Peer objects
Browse files Browse the repository at this point in the history
Suggested here: bitcoin#19607 (comment)
  • Loading branch information
jnewbery committed Aug 28, 2020
1 parent 1cf73fb commit 283995b
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,10 @@ void PeerLogicValidation::FinalizeNode(NodeId nodeid, bool& fUpdateConnectionTim
LOCK(cs_main);
int misbehavior{0};
{
// We remove the Peer object from g_peer_map here, but it's not guaranteed that
// we'll destruct Peer here since another thread could potentially still hold
// a reference to the object. Be careful not to do any processing here that
// assumes Peer won't be changed before it's destructed.
PeerRef peer = GetPeerRef(nodeid);
assert(peer != nullptr);
misbehavior = WITH_LOCK(peer->m_misbehavior_mutex, return peer->m_misbehavior_score);
Expand Down

0 comments on commit 283995b

Please sign in to comment.