net: avoid uninitialized reads on counters

Initialize CConnman byte counters during construction, so that
GetTotalBytesRecv() and GetTotalBytesSent() methods don't return
garbage before Start() is called, in QT.

Backported from: 8313fa8e
Original author: Russell Yanofsky <russ@yanofsky.org>
This commit is contained in:
Patrick Lodder 2021-12-17 19:45:45 -04:00
parent 7019ead6a1
commit 39a476dcb2
No known key found for this signature in database
GPG Key ID: 7C523F5FBABE80E7
2 changed files with 2 additions and 4 deletions

View File

@ -2217,8 +2217,6 @@ NodeId CConnman::GetNewNodeId()
bool CConnman::Start(CScheduler& scheduler, std::string& strNodeError, Options connOptions)
{
nTotalBytesRecv = 0;
nTotalBytesSent = 0;
nMaxOutboundTotalBytesSentInCycle = 0;
nMaxOutboundCycleStartTime = 0;

View File

@ -339,8 +339,8 @@ private:
// Network usage totals
CCriticalSection cs_totalBytesRecv;
CCriticalSection cs_totalBytesSent;
uint64_t nTotalBytesRecv;
uint64_t nTotalBytesSent;
uint64_t nTotalBytesRecv = 0;
uint64_t nTotalBytesSent = 0;
// outbound limit & stats
uint64_t nMaxOutboundTotalBytesSentInCycle;