Skip to content

Commit

Permalink
Use unique_ptr for pfilter (CBloomFilter)
Browse files Browse the repository at this point in the history
  • Loading branch information
practicalswift authored and random-zebra committed Jul 25, 2021
1 parent ff1c454 commit 36108b9
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 8 deletions.
4 changes: 1 addition & 3 deletions src/net.cpp
Expand Up @@ -2332,7 +2332,7 @@ CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn
nNextLocalAddrSend = 0;
nNextAddrSend = 0;
fRelayTxes = false;
pfilter = new CBloomFilter();
pfilter = std::unique_ptr<CBloomFilter>(new CBloomFilter());
timeLastMempoolReq = 0;
nPingNonceSent = 0;
nPingUsecStart = 0;
Expand All @@ -2356,8 +2356,6 @@ CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn
CNode::~CNode()
{
CloseSocket(hSocket);

delete pfilter;
}

void CNode::AskFor(const CInv& inv)
Expand Down
2 changes: 1 addition & 1 deletion src/net.h
Expand Up @@ -570,7 +570,7 @@ class CNode
bool fRelayTxes; //protected by cs_filter
CSemaphoreGrant grantOutbound;
RecursiveMutex cs_filter;
CBloomFilter* pfilter;
std::unique_ptr<CBloomFilter> pfilter;
std::atomic<int> nRefCount;
const NodeId id;

Expand Down
6 changes: 2 additions & 4 deletions src/net_processing.cpp
Expand Up @@ -1836,8 +1836,7 @@ bool static ProcessMessage(CNode* pfrom, std::string strCommand, CDataStream& vR
LOCK(cs_main);
Misbehaving(pfrom->GetId(), 100);
} else {
delete pfrom->pfilter;
pfrom->pfilter = new CBloomFilter(filter);
pfrom->pfilter.reset(new CBloomFilter(filter));
pfrom->pfilter->UpdateEmptyFull();
pfrom->fRelayTxes = true;
}
Expand Down Expand Up @@ -1870,8 +1869,7 @@ bool static ProcessMessage(CNode* pfrom, std::string strCommand, CDataStream& vR

else if (strCommand == NetMsgType::FILTERCLEAR) {
LOCK(pfrom->cs_filter);
delete pfrom->pfilter;
pfrom->pfilter = new CBloomFilter();
pfrom->pfilter.reset(new CBloomFilter());
pfrom->fRelayTxes = true;
}

Expand Down

0 comments on commit 36108b9

Please sign in to comment.