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 committed Nov 9, 2017
1 parent 8ccf1bb commit f72cbf9
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 @@ -2741,7 +2741,7 @@ CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn
nNextInvSend = 0;
fRelayTxes = false;
fSentAddr = false;
pfilter = new CBloomFilter();
pfilter = std::unique_ptr<CBloomFilter>(new CBloomFilter());
timeLastMempoolReq = 0;
nLastBlockTime = 0;
nLastTXTime = 0;
Expand Down Expand Up @@ -2771,8 +2771,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 @@ -648,7 +648,7 @@ class CNode
bool fSentAddr;
CSemaphoreGrant grantOutbound;
CCriticalSection cs_filter;
CBloomFilter* pfilter;
std::unique_ptr<CBloomFilter> pfilter;
std::atomic<int> nRefCount;

const uint64_t nKeyedNetGroup;
Expand Down
6 changes: 2 additions & 4 deletions src/net_processing.cpp
Expand Up @@ -2755,8 +2755,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
else
{
LOCK(pfrom->cs_filter);
delete pfrom->pfilter;
pfrom->pfilter = new CBloomFilter(filter);
pfrom->pfilter.reset(new CBloomFilter(filter));
pfrom->pfilter->UpdateEmptyFull();
pfrom->fRelayTxes = true;
}
Expand Down Expand Up @@ -2792,8 +2791,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
{
LOCK(pfrom->cs_filter);
if (pfrom->GetLocalServices() & NODE_BLOOM) {
delete pfrom->pfilter;
pfrom->pfilter = new CBloomFilter();
pfrom->pfilter.reset(new CBloomFilter());
}
pfrom->fRelayTxes = true;
}
Expand Down

0 comments on commit f72cbf9

Please sign in to comment.