Skip to content

Commit 8ccf1bb

Browse files
Use unique_ptr for sem{Addnode,Outbound} (CSemaphore)
1 parent 73db063 commit 8ccf1bb

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

src/net.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2222,8 +2222,6 @@ CConnman::CConnman(uint64_t nSeed0In, uint64_t nSeed1In) : nSeed0(nSeed0In), nSe
22222222
nLastNodeId = 0;
22232223
nSendBufferMaxSize = 0;
22242224
nReceiveFloodSize = 0;
2225-
semOutbound = nullptr;
2226-
semAddnode = nullptr;
22272225
flagInterruptMsgProc = false;
22282226
SetTryNewOutboundPeer(false);
22292227

@@ -2329,11 +2327,11 @@ bool CConnman::Start(CScheduler& scheduler, const Options& connOptions)
23292327

23302328
if (semOutbound == nullptr) {
23312329
// initialize semaphore
2332-
semOutbound = new CSemaphore(std::min((nMaxOutbound + nMaxFeeler), nMaxConnections));
2330+
semOutbound = std::unique_ptr<CSemaphore>(new CSemaphore(std::min((nMaxOutbound + nMaxFeeler), nMaxConnections)));
23332331
}
23342332
if (semAddnode == nullptr) {
23352333
// initialize semaphore
2336-
semAddnode = new CSemaphore(nMaxAddnode);
2334+
semAddnode = std::unique_ptr<CSemaphore>(new CSemaphore(nMaxAddnode));
23372335
}
23382336

23392337
//
@@ -2456,10 +2454,8 @@ void CConnman::Stop()
24562454
vNodes.clear();
24572455
vNodesDisconnected.clear();
24582456
vhListenSocket.clear();
2459-
delete semOutbound;
2460-
semOutbound = nullptr;
2461-
delete semAddnode;
2462-
semAddnode = nullptr;
2457+
semOutbound.reset();
2458+
semAddnode.reset();
24632459
}
24642460

24652461
void CConnman::DeleteNode(CNode* pnode)

src/net.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,8 +399,8 @@ class CConnman
399399
/** Services this instance offers */
400400
ServiceFlags nLocalServices;
401401

402-
CSemaphore *semOutbound;
403-
CSemaphore *semAddnode;
402+
std::unique_ptr<CSemaphore> semOutbound;
403+
std::unique_ptr<CSemaphore> semAddnode;
404404
int nMaxConnections;
405405
int nMaxOutbound;
406406
int nMaxAddnode;

0 commit comments

Comments
 (0)