From 36108b95bfff1ac20f362c853e53fe86e96f7368 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 06810dae2b044..d47065db82ab1 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -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(new CBloomFilter()); timeLastMempoolReq = 0; nPingNonceSent = 0; nPingUsecStart = 0; @@ -2356,8 +2356,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 8e9674f5c5243..860f7aac9963f 100644 --- a/src/net.h +++ b/src/net.h @@ -570,7 +570,7 @@ class CNode bool fRelayTxes; //protected by cs_filter CSemaphoreGrant grantOutbound; RecursiveMutex cs_filter; - CBloomFilter* pfilter; + std::unique_ptr pfilter; std::atomic nRefCount; const NodeId id; diff --git a/src/net_processing.cpp b/src/net_processing.cpp index cd2f91694fcd1..4650a82246a30 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -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; } @@ -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; }