Skip to content

Commit 63f21d2

Browse files
net: Add missing locks in net.{cpp,h}
* writing variable 'nTotalBytesRecv' requires holding mutex 'cs_totalBytesRecv' exclusively * writing variables 'nTotalBytesSent'/'nMaxOutboundTotalBytesSentInCycle'/'nMaxOutboundCycleStartTime' require holding mutex 'cs_totalBytesSent' exclusively * writing variable 'nMaxOutboundTimeframe'/'nMaxOutboundLimit' require holding mutex 'cs_totalBytesSent' exclusively * writing variable 'vAddedNodes' requires holding mutex 'cs_vAddedNodes' exclusively
1 parent d4267a3 commit 63f21d2

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

src/net.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2269,10 +2269,16 @@ bool CConnman::Start(CScheduler& scheduler, const Options& connOptions)
22692269
{
22702270
Init(connOptions);
22712271

2272-
nTotalBytesRecv = 0;
2273-
nTotalBytesSent = 0;
2274-
nMaxOutboundTotalBytesSentInCycle = 0;
2275-
nMaxOutboundCycleStartTime = 0;
2272+
{
2273+
LOCK(cs_totalBytesRecv);
2274+
nTotalBytesRecv = 0;
2275+
}
2276+
{
2277+
LOCK(cs_totalBytesSent);
2278+
nTotalBytesSent = 0;
2279+
nMaxOutboundTotalBytesSentInCycle = 0;
2280+
nMaxOutboundCycleStartTime = 0;
2281+
}
22762282

22772283
if (fListen && !InitBinds(connOptions.vBinds, connOptions.vWhiteBinds)) {
22782284
if (clientInterface) {

src/net.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,16 @@ class CConnman
158158
m_msgproc = connOptions.m_msgproc;
159159
nSendBufferMaxSize = connOptions.nSendBufferMaxSize;
160160
nReceiveFloodSize = connOptions.nReceiveFloodSize;
161-
nMaxOutboundTimeframe = connOptions.nMaxOutboundTimeframe;
162-
nMaxOutboundLimit = connOptions.nMaxOutboundLimit;
161+
{
162+
LOCK(cs_totalBytesSent);
163+
nMaxOutboundTimeframe = connOptions.nMaxOutboundTimeframe;
164+
nMaxOutboundLimit = connOptions.nMaxOutboundLimit;
165+
}
163166
vWhitelistedRange = connOptions.vWhitelistedRange;
164-
vAddedNodes = connOptions.m_added_nodes;
167+
{
168+
LOCK(cs_vAddedNodes);
169+
vAddedNodes = connOptions.m_added_nodes;
170+
}
165171
}
166172

167173
CConnman(uint64_t seed0, uint64_t seed1);

0 commit comments

Comments
 (0)