Skip to content

Commit

Permalink
Use unique_ptr for sem{Addnode,Outbound} (CSemaphore)
Browse files Browse the repository at this point in the history
  • Loading branch information
practicalswift authored and random-zebra committed Jul 25, 2021
1 parent 93daf17 commit ff1c454
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
10 changes: 4 additions & 6 deletions src/net.cpp
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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<CSemaphore>(new CSemaphore(std::min((nMaxOutbound + nMaxFeeler), nMaxConnections)));
}

if (pnodeLocalHost == nullptr) {
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/net.h
Expand Up @@ -355,7 +355,7 @@ class CConnman
/** Services this instance cares about */
ServiceFlags nRelevantServices{NODE_NONE};

CSemaphore *semOutbound{nullptr};
std::unique_ptr<CSemaphore> semOutbound;
int nMaxConnections{0};
int nMaxOutbound{0};
int nMaxFeeler{0};
Expand Down

0 comments on commit ff1c454

Please sign in to comment.