aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpracticalswift <practicalswift@users.noreply.github.com>2017-08-09 16:07:22 +0200
committerpracticalswift <practicalswift@users.noreply.github.com>2017-11-09 16:52:44 +0100
commit8ccf1bb0c31108762e47f28d9d592e8d4c788564 (patch)
treedf1f221b3c3e7d28b743b99b259eb964cde4dff7
parent73db0635a38744b09058b590ac246af5499630c9 (diff)
Use unique_ptr for sem{Addnode,Outbound} (CSemaphore)
-rw-r--r--src/net.cpp12
-rw-r--r--src/net.h4
2 files changed, 6 insertions, 10 deletions
diff --git a/src/net.cpp b/src/net.cpp
index 2db1f2a04f..5f0a7a4770 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -2222,8 +2222,6 @@ CConnman::CConnman(uint64_t nSeed0In, uint64_t nSeed1In) : nSeed0(nSeed0In), nSe
nLastNodeId = 0;
nSendBufferMaxSize = 0;
nReceiveFloodSize = 0;
- semOutbound = nullptr;
- semAddnode = nullptr;
flagInterruptMsgProc = false;
SetTryNewOutboundPeer(false);
@@ -2329,11 +2327,11 @@ bool CConnman::Start(CScheduler& scheduler, const Options& connOptions)
if (semOutbound == nullptr) {
// initialize semaphore
- semOutbound = new CSemaphore(std::min((nMaxOutbound + nMaxFeeler), nMaxConnections));
+ semOutbound = std::unique_ptr<CSemaphore>(new CSemaphore(std::min((nMaxOutbound + nMaxFeeler), nMaxConnections)));
}
if (semAddnode == nullptr) {
// initialize semaphore
- semAddnode = new CSemaphore(nMaxAddnode);
+ semAddnode = std::unique_ptr<CSemaphore>(new CSemaphore(nMaxAddnode));
}
//
@@ -2456,10 +2454,8 @@ void CConnman::Stop()
vNodes.clear();
vNodesDisconnected.clear();
vhListenSocket.clear();
- delete semOutbound;
- semOutbound = nullptr;
- delete semAddnode;
- semAddnode = nullptr;
+ semOutbound.reset();
+ semAddnode.reset();
}
void CConnman::DeleteNode(CNode* pnode)
diff --git a/src/net.h b/src/net.h
index edca1171ab..668e92c004 100644
--- a/src/net.h
+++ b/src/net.h
@@ -399,8 +399,8 @@ private:
/** Services this instance offers */
ServiceFlags nLocalServices;
- CSemaphore *semOutbound;
- CSemaphore *semAddnode;
+ std::unique_ptr<CSemaphore> semOutbound;
+ std::unique_ptr<CSemaphore> semAddnode;
int nMaxConnections;
int nMaxOutbound;
int nMaxAddnode;