From f72cbf9ba970e997be84fb7b20795c6b9c62fb42 Mon Sep 17 00:00:00 2001 From: practicalswift Date: Wed, 9 Aug 2017 16:14:37 +0200 Subject: [PATCH] Use unique_ptr for pfilter (CBloomFilter) --- src/net.cpp | 4 +--- src/net.h | 2 +- src/net_processing.cpp | 6 ++---- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/net.cpp b/src/net.cpp index 5f0a7a477..6b0c131cf 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -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(new CBloomFilter()); timeLastMempoolReq = 0; nLastBlockTime = 0; nLastTXTime = 0; @@ -2771,8 +2771,6 @@ CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn CNode::~CNode() { CloseSocket(hSocket); - - delete pfilter; } void CNode::AskFor(const CInv& inv) diff --git a/src/net.h b/src/net.h index 668e92c00..8cb00dd5a 100644 --- a/src/net.h +++ b/src/net.h @@ -648,7 +648,7 @@ public: bool fSentAddr; CSemaphoreGrant grantOutbound; CCriticalSection cs_filter; - CBloomFilter* pfilter; + std::unique_ptr pfilter; std::atomic nRefCount; const uint64_t nKeyedNetGroup; diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 6866cd340..3b26a98f4 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -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; } @@ -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; } -- 2.11.4.GIT