Ref T730, replaced uint array by vector to avoid memory leak

* the heap array was not deleted
* using QVector<uint> now
* const correctness
This commit is contained in:
Klaus Basan
2019-09-29 01:01:28 +02:00
committed by Mat Sutcliffe
parent c3684a2f8c
commit 5f6aebebe8
2 changed files with 20 additions and 23 deletions

View File

@@ -16,28 +16,26 @@ namespace BlackCore
{
CCryptoDtoChannel::CCryptoDtoChannel(QString channelTag, const QByteArray &aeadReceiveKey, const QByteArray &aeadTransmitKey, int receiveSequenceHistorySize)
{
m_channelTag = channelTag;
m_aeadReceiveKey = aeadReceiveKey;
m_channelTag = channelTag;
m_aeadReceiveKey = aeadReceiveKey;
m_aeadTransmitKey = aeadTransmitKey;
m_receiveSequenceSizeMaxSize = receiveSequenceHistorySize;
if (m_receiveSequenceSizeMaxSize < 1)
m_receiveSequenceSizeMaxSize = 1;
m_receiveSequenceHistory = new uint[m_receiveSequenceSizeMaxSize];
if (m_receiveSequenceSizeMaxSize < 1) { m_receiveSequenceSizeMaxSize = 1; }
m_receiveSequenceHistory.fill(0, m_receiveSequenceSizeMaxSize);
m_receiveSequenceHistoryDepth = 0;
}
CCryptoDtoChannel::CCryptoDtoChannel(CryptoDtoChannelConfigDto channelConfig, int receiveSequenceHistorySize)
{
m_channelTag = channelConfig.channelTag;
m_aeadReceiveKey = channelConfig.aeadReceiveKey;
m_channelTag = channelConfig.channelTag;
m_aeadReceiveKey = channelConfig.aeadReceiveKey;
m_aeadTransmitKey = channelConfig.aeadTransmitKey;
m_hmacKey = channelConfig.hmacKey;
m_hmacKey = channelConfig.hmacKey;
m_receiveSequenceSizeMaxSize = receiveSequenceHistorySize;
if (m_receiveSequenceSizeMaxSize < 1)
m_receiveSequenceSizeMaxSize = 1;
m_receiveSequenceHistory = new uint[m_receiveSequenceSizeMaxSize];
if (m_receiveSequenceSizeMaxSize < 1) { m_receiveSequenceSizeMaxSize = 1; }
m_receiveSequenceHistory.fill(0, m_receiveSequenceSizeMaxSize);
m_receiveSequenceHistoryDepth = 0;
}
@@ -113,20 +111,19 @@ namespace BlackCore
return true;
}
bool CCryptoDtoChannel::contains(uint sequence)
bool CCryptoDtoChannel::contains(uint sequence) const
{
for (int i = 0; i < m_receiveSequenceHistoryDepth; i++)
{
if (m_receiveSequenceHistory[i] == sequence)
return true;
if (m_receiveSequenceHistory[i] == sequence) { return true; }
}
return false;
}
uint CCryptoDtoChannel::getMin(int &minIndex)
uint CCryptoDtoChannel::getMin(int &minIndex) const
{
uint minValue = std::numeric_limits<uint>::max();
minIndex = -1;
minIndex = -1;
int index = -1;
for (int i = 0; i < m_receiveSequenceHistoryDepth; i++)
@@ -140,7 +137,6 @@ namespace BlackCore
}
return minValue;
}
} // ns
} // ns
} // ns

View File

@@ -16,6 +16,7 @@
#include <QDateTime>
#include <QByteArray>
#include <QVector>
#include <limits>
@@ -50,21 +51,21 @@ namespace BlackCore
bool checkReceivedSequence(uint sequenceReceived);
private:
bool contains(uint sequence);
uint getMin(int &minIndex);
bool contains(uint sequence) const;
uint getMin(int &minIndex) const;
QByteArray m_aeadTransmitKey;
QByteArray m_aeadReceiveKey;
uint m_transmitSequence = 0;
uint *m_receiveSequenceHistory;
QVector<uint> m_receiveSequenceHistory;
int m_receiveSequenceHistoryDepth;
int m_receiveSequenceSizeMaxSize;
QByteArray m_hmacKey;
QString m_channelTag;
QDateTime m_LastTransmitUtc;
QDateTime m_lastReceiveUtc;
QString m_channelTag;
QDateTime m_LastTransmitUtc;
QDateTime m_lastReceiveUtc;
};
} // ns
} // ns