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 Oct 19, 2020
1 parent d9d9a29 commit d8a2ad4
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,11 @@ void PeerManager::FinalizeNode(NodeId nodeid, bool& fUpdateConnectionTime) {
LOCK(cs_main);
int misbehavior{0};
{
// We remove the PeerRef from g_peer_map here, but we don't always
// destruct the Peer. Sometimes another thread is still holding a
// PeerRef, so the refcount is >= 1. 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 d8a2ad4

Please sign in to comment.