From 6f67b462980d36ced3705b23c5c8c6a575844da2 Mon Sep 17 00:00:00 2001 From: Tom Early Date: Thu, 2 Jul 2020 10:38:10 -0700 Subject: [PATCH] Fix orphaned Frame memory leak --- src/cprotocol.cpp | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/cprotocol.cpp b/src/cprotocol.cpp index 7fd4967..12661eb 100644 --- a/src/cprotocol.cpp +++ b/src/cprotocol.cpp @@ -19,7 +19,7 @@ // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License -// along with Foobar. If not, see . +// along with Foobar. If not, see . // ---------------------------------------------------------------------------- #include "main.h" @@ -52,7 +52,7 @@ CProtocol::~CProtocol() m_pThread->join(); delete m_pThread; } - + // empty queue m_Queue.Lock(); while ( !m_Queue.empty() ) @@ -69,13 +69,13 @@ bool CProtocol::Init(void) { // init reflector apparent callsign m_ReflectorCallsign = g_Reflector.GetCallsign(); - + // reset stop flag m_bStopThread = false; // start thread; m_pThread = new std::thread(CProtocol::Thread, this); - + // done return true; } @@ -138,7 +138,12 @@ void CProtocol::OnDvFramePacketIn(CDvFramePacket *Frame, const CIp *Ip) { // find the stream CPacketStream *stream = GetStream(Frame->GetStreamId(), Ip); - if ( stream != NULL ) + if ( stream == NULL ) + { + std::cout << "Deleting oprhaned Frame Packet with StreamId " << Frame->GetStreamId() << " from " << *Ip << std::endl; + delete Frame; + } + else { //std::cout << "DV frame" << "from " << *Ip << std::endl; // and push @@ -152,13 +157,18 @@ void CProtocol::OnDvLastFramePacketIn(CDvLastFramePacket *Frame, const CIp *Ip) { // find the stream CPacketStream *stream = GetStream(Frame->GetStreamId(), Ip); - if ( stream != NULL ) + if ( stream == NULL ) + { + std::cout << "Deleting oprhaned Last Frame Packet with StreamId " << Frame->GetStreamId() << " from " << *Ip << std::endl; + delete Frame; + } + else { // push stream->Lock(); stream->Push(Frame); stream->Unlock(); - + // and close the stream g_Reflector.CloseStream(stream); } @@ -170,7 +180,7 @@ void CProtocol::OnDvLastFramePacketIn(CDvLastFramePacket *Frame, const CIp *Ip) CPacketStream *CProtocol::GetStream(uint16 uiStreamId, const CIp *Ip) { CPacketStream *stream = NULL; - + // find if we have a stream with same streamid in our cache for ( int i = 0; (i < m_Streams.size()) && (stream == NULL); i++ ) { @@ -256,5 +266,3 @@ uint32 CProtocol::ModuleToDmrDestId(char m) const { return (uint32)(m - 'A')+1; } - -