Skip to content

Commit f72cbf9

Browse files
Use unique_ptr for pfilter (CBloomFilter)
1 parent 8ccf1bb commit f72cbf9

File tree

3 files changed

+4
-8
lines changed

3 files changed

+4
-8
lines changed

src/net.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2741,7 +2741,7 @@ CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn
27412741
nNextInvSend = 0;
27422742
fRelayTxes = false;
27432743
fSentAddr = false;
2744-
pfilter = new CBloomFilter();
2744+
pfilter = std::unique_ptr<CBloomFilter>(new CBloomFilter());
27452745
timeLastMempoolReq = 0;
27462746
nLastBlockTime = 0;
27472747
nLastTXTime = 0;
@@ -2771,8 +2771,6 @@ CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn
27712771
CNode::~CNode()
27722772
{
27732773
CloseSocket(hSocket);
2774-
2775-
delete pfilter;
27762774
}
27772775

27782776
void CNode::AskFor(const CInv& inv)

src/net.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ class CNode
648648
bool fSentAddr;
649649
CSemaphoreGrant grantOutbound;
650650
CCriticalSection cs_filter;
651-
CBloomFilter* pfilter;
651+
std::unique_ptr<CBloomFilter> pfilter;
652652
std::atomic<int> nRefCount;
653653

654654
const uint64_t nKeyedNetGroup;

src/net_processing.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2755,8 +2755,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
27552755
else
27562756
{
27572757
LOCK(pfrom->cs_filter);
2758-
delete pfrom->pfilter;
2759-
pfrom->pfilter = new CBloomFilter(filter);
2758+
pfrom->pfilter.reset(new CBloomFilter(filter));
27602759
pfrom->pfilter->UpdateEmptyFull();
27612760
pfrom->fRelayTxes = true;
27622761
}
@@ -2792,8 +2791,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
27922791
{
27932792
LOCK(pfrom->cs_filter);
27942793
if (pfrom->GetLocalServices() & NODE_BLOOM) {
2795-
delete pfrom->pfilter;
2796-
pfrom->pfilter = new CBloomFilter();
2794+
pfrom->pfilter.reset(new CBloomFilter());
27972795
}
27982796
pfrom->fRelayTxes = true;
27992797
}

0 commit comments

Comments
 (0)