Skip to content

Commit

Permalink
fix various valgrind reports;
Browse files Browse the repository at this point in the history
  • Loading branch information
gatekeep committed Jul 16, 2024
1 parent 22d13e4 commit 47d89fe
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/common/network/FrameQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ bool FrameQueue::write(const uint8_t* message, uint32_t length, uint32_t streamI
ret = false;
}

delete buffer;
delete[] buffer;
return ret;
}

Expand Down
2 changes: 1 addition & 1 deletion src/common/network/RawFrameQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ void RawFrameQueue::deleteBuffers()
if (buffer != nullptr) {
// LogDebug(LOG_NET, "deleting buffer, addr %p len %u", buffer->buffer, buffer->length);
if (buffer->buffer != nullptr) {
delete buffer->buffer;
delete[] buffer->buffer;
buffer->length = 0;
buffer->buffer = nullptr;
}
Expand Down
35 changes: 19 additions & 16 deletions src/common/p25/dfsi/LC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,24 +58,26 @@ LC::LC(const LC& data) : LC()

LC::LC(const lc::LC& control, const data::LowSpeedData& lsd) : LC()
{
if (m_control != nullptr)
delete m_control;
m_control = new lc::LC(control);

if (m_lsd != nullptr)
delete m_lsd;
m_lsd = new data::LowSpeedData(lsd);
}

/* Finalizes a instance of LC class. */

LC::~LC()
{
if (m_control != nullptr) {
if (m_control != nullptr)
delete m_control;
}
if (m_lsd != nullptr) {
if (m_lsd != nullptr)
delete m_lsd;
}
delete[] m_mi;
if (m_rsBuffer != nullptr) {
if (m_rsBuffer != nullptr)
delete[] m_rsBuffer;
}
}

/* Equals operator. */
Expand Down Expand Up @@ -113,18 +115,16 @@ bool LC::decodeLDU1(const uint8_t* data, uint8_t* imbe)
{
case DFSIFrameType::LDU1_VOICE1:
{
if (m_control != nullptr) {
if (m_control != nullptr)
delete m_control;
}
m_control = new lc::LC();

if (m_lsd != nullptr) {
m_lsd = new data::LowSpeedData();
}
if (m_lsd != nullptr)
delete m_lsd;
m_lsd = new data::LowSpeedData();

if (m_rsBuffer != nullptr) {
delete m_rsBuffer;
}
if (m_rsBuffer != nullptr)
delete[] m_rsBuffer;
m_rsBuffer = new uint8_t[P25_LDU_LC_FEC_LENGTH_BYTES];
::memset(m_rsBuffer, 0x00U, P25_LDU_LC_FEC_LENGTH_BYTES);

Expand Down Expand Up @@ -424,9 +424,8 @@ bool LC::decodeLDU2(const uint8_t* data, uint8_t* imbe)
case DFSIFrameType::LDU2_VOICE10:
{
::memset(m_mi, 0x00U, MI_LENGTH_BYTES);
if (m_lsd != nullptr) {
if (m_lsd != nullptr)
delete m_lsd;
}
m_lsd = new data::LowSpeedData();

m_rssi = data[6U]; // RSSI
Expand Down Expand Up @@ -661,7 +660,11 @@ void LC::copy(const LC& data)

m_rssi = data.m_rssi;

if (m_control != nullptr)
delete m_control;
m_control = new lc::LC(*data.m_control);
if (m_lsd != nullptr)
delete m_lsd;
m_lsd = new data::LowSpeedData(*data.m_lsd);

delete[] m_mi;
Expand Down
4 changes: 4 additions & 0 deletions src/common/p25/lc/LC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,8 @@ bool LC::decodeLDU2(const uint8_t* data)

m_algId = rs[9U]; // Algorithm ID
if (m_algId != ALGO_UNENCRYPT) {
if (m_mi != nullptr)
delete[] m_mi;
m_mi = new uint8_t[MI_LENGTH_BYTES];
::memset(m_mi, 0x00U, MI_LENGTH_BYTES);
::memcpy(m_mi, rs, MI_LENGTH_BYTES); // Message Indicator
Expand All @@ -371,6 +373,8 @@ bool LC::decodeLDU2(const uint8_t* data)
}
}
else {
if (m_mi != nullptr)
delete[] m_mi;
m_mi = new uint8_t[MI_LENGTH_BYTES];
::memset(m_mi, 0x00U, MI_LENGTH_BYTES);

Expand Down
3 changes: 2 additions & 1 deletion src/fne/network/DiagNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ void DiagNetwork::processNetwork()
::memcpy(req->buffer, buffer.get(), length);

if (!Thread::runAsThread(m_fneNetwork, threadedNetworkRx, req)) {
delete[] req->buffer;
delete req;
return;
}
Expand Down Expand Up @@ -310,7 +311,7 @@ void* DiagNetwork::threadedNetworkRx(void* arg)
}

if (req->buffer != nullptr)
delete req->buffer;
delete[] req->buffer;
delete req;
}

Expand Down
3 changes: 2 additions & 1 deletion src/fne/network/FNENetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ void FNENetwork::processNetwork()
::memcpy(req->buffer, buffer.get(), length);

if (!Thread::runAsThread(this, threadedNetworkRx, req)) {
delete[] req->buffer;
delete req;
return;
}
Expand Down Expand Up @@ -1170,7 +1171,7 @@ void* FNENetwork::threadedNetworkRx(void* arg)
}

if (req->buffer != nullptr)
delete req->buffer;
delete[] req->buffer;
delete req;
}

Expand Down
9 changes: 6 additions & 3 deletions src/fne/network/callhandler/TagDMRData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ TagDMRData::TagDMRData(FNENetwork* network, bool debug) :

/* Finalizes a instance of the TagDMRData class. */

TagDMRData::~TagDMRData() = default;
TagDMRData::~TagDMRData()
{
delete m_packetData;
}

/* Process a data frame from the network. */

Expand Down Expand Up @@ -203,7 +206,7 @@ bool TagDMRData::processFrame(const uint8_t* data, uint32_t len, uint32_t peerId
if (m_parrotFrames.size() > 0) {
for (auto& pkt : m_parrotFrames) {
if (pkt.buffer != nullptr) {
delete pkt.buffer;
delete[] pkt.buffer;
}
}
m_parrotFrames.clear();
Expand Down Expand Up @@ -410,7 +413,7 @@ void TagDMRData::playbackParrot()
}
}

delete pkt.buffer;
delete[] pkt.buffer;
}
Thread::sleep(60);
m_parrotFrames.pop_front();
Expand Down
4 changes: 2 additions & 2 deletions src/fne/network/callhandler/TagNXDNData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ bool TagNXDNData::processFrame(const uint8_t* data, uint32_t len, uint32_t peerI
if (m_parrotFrames.size() > 0) {
for (auto& pkt : m_parrotFrames) {
if (pkt.buffer != nullptr) {
delete pkt.buffer;
delete[] pkt.buffer;
}
}
m_parrotFrames.clear();
Expand Down Expand Up @@ -366,7 +366,7 @@ void TagNXDNData::playbackParrot()
}
}

delete pkt.buffer;
delete[] pkt.buffer;
}
Thread::sleep(60);
m_parrotFrames.pop_front();
Expand Down
4 changes: 2 additions & 2 deletions src/fne/network/callhandler/TagP25Data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ bool TagP25Data::processFrame(const uint8_t* data, uint32_t len, uint32_t peerId
if (m_parrotFrames.size() > 0) {
for (auto& pkt : m_parrotFrames) {
if (pkt.buffer != nullptr) {
delete pkt.buffer;
delete[] pkt.buffer;
}
}
m_parrotFrames.clear();
Expand Down Expand Up @@ -492,7 +492,7 @@ void TagP25Data::playbackParrot()
}
}

delete pkt.buffer;
delete[] pkt.buffer;
}
Thread::sleep(180);
m_parrotFrames.pop_front();
Expand Down
7 changes: 7 additions & 0 deletions src/host/p25/Control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,13 @@ Control::~Control()
if (m_data != nullptr) {
delete m_data;
}

if (m_llaK != nullptr) {
delete[] m_llaK;
}
delete[] m_llaRS;
delete[] m_llaCRS;
delete[] m_llaKS;
}

/* Resets the data states for the RF interface. */
Expand Down

0 comments on commit 47d89fe

Please sign in to comment.