From ff1c454b8ab32fd8413d6715d83d88444f6d9a18 Mon Sep 17 00:00:00 2001 From: practicalswift Date: Wed, 9 Aug 2017 16:07:22 +0200 Subject: [PATCH] Use unique_ptr for sem{Addnode,Outbound} (CSemaphore) --- src/net.cpp | 10 ++++------ src/net.h | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/net.cpp b/src/net.cpp index 68c3593db66cb..06810dae2b044 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -1914,11 +1914,10 @@ CConnman::CConnman(uint64_t nSeed0In, uint64_t nSeed1In) : nSeed0(nSeed0In), nSe nLastNodeId = 0; nSendBufferMaxSize = 0; nReceiveFloodSize = 0; - semOutbound = NULL; nMaxConnections = 0; nMaxOutbound = 0; nBestHeight = 0; - clientInterface = NULL; + clientInterface = nullptr; flagInterruptMsgProc = false; } @@ -1984,9 +1983,9 @@ bool CConnman::Start(CScheduler& scheduler, std::string& strNodeError, Options c fAddressesInitialized = true; - if (semOutbound == NULL) { + if (semOutbound == nullptr) { // initialize semaphore - semOutbound = new CSemaphore(std::min((nMaxOutbound + nMaxFeeler), nMaxConnections)); + semOutbound = std::unique_ptr(new CSemaphore(std::min((nMaxOutbound + nMaxFeeler), nMaxConnections))); } if (pnodeLocalHost == nullptr) { @@ -2113,8 +2112,7 @@ void CConnman::Stop() vNodes.clear(); vNodesDisconnected.clear(); vhListenSocket.clear(); - delete semOutbound; - semOutbound = NULL; + semOutbound.reset(); if(pnodeLocalHost) DeleteNode(pnodeLocalHost); pnodeLocalHost = NULL; diff --git a/src/net.h b/src/net.h index 1f82d0b8d8880..8e9674f5c5243 100644 --- a/src/net.h +++ b/src/net.h @@ -355,7 +355,7 @@ class CConnman /** Services this instance cares about */ ServiceFlags nRelevantServices{NODE_NONE}; - CSemaphore *semOutbound{nullptr}; + std::unique_ptr semOutbound; int nMaxConnections{0}; int nMaxOutbound{0}; int nMaxFeeler{0};