Merge pull request #170 from n7tae/master

Fix orphaned Frame memory leak
This commit is contained in:
LX3JL 2020-07-03 09:30:19 +02:00 committed by GitHub
commit a70295c621
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 10 deletions

View File

@ -19,7 +19,7 @@
// GNU General Public License for more details. // GNU General Public License for more details.
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Foobar. If not, see <http://www.gnu.org/licenses/>. // along with Foobar. If not, see <http://www.gnu.org/licenses/>.
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
#include "main.h" #include "main.h"
@ -52,7 +52,7 @@ CProtocol::~CProtocol()
m_pThread->join(); m_pThread->join();
delete m_pThread; delete m_pThread;
} }
// empty queue // empty queue
m_Queue.Lock(); m_Queue.Lock();
while ( !m_Queue.empty() ) while ( !m_Queue.empty() )
@ -69,13 +69,13 @@ bool CProtocol::Init(void)
{ {
// init reflector apparent callsign // init reflector apparent callsign
m_ReflectorCallsign = g_Reflector.GetCallsign(); m_ReflectorCallsign = g_Reflector.GetCallsign();
// reset stop flag // reset stop flag
m_bStopThread = false; m_bStopThread = false;
// start thread; // start thread;
m_pThread = new std::thread(CProtocol::Thread, this); m_pThread = new std::thread(CProtocol::Thread, this);
// done // done
return true; return true;
} }
@ -138,7 +138,12 @@ void CProtocol::OnDvFramePacketIn(CDvFramePacket *Frame, const CIp *Ip)
{ {
// find the stream // find the stream
CPacketStream *stream = GetStream(Frame->GetStreamId(), Ip); 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; //std::cout << "DV frame" << "from " << *Ip << std::endl;
// and push // and push
@ -152,13 +157,18 @@ void CProtocol::OnDvLastFramePacketIn(CDvLastFramePacket *Frame, const CIp *Ip)
{ {
// find the stream // find the stream
CPacketStream *stream = GetStream(Frame->GetStreamId(), Ip); 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 // push
stream->Lock(); stream->Lock();
stream->Push(Frame); stream->Push(Frame);
stream->Unlock(); stream->Unlock();
// and close the stream // and close the stream
g_Reflector.CloseStream(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 *CProtocol::GetStream(uint16 uiStreamId, const CIp *Ip)
{ {
CPacketStream *stream = NULL; CPacketStream *stream = NULL;
// find if we have a stream with same streamid in our cache // find if we have a stream with same streamid in our cache
for ( int i = 0; (i < m_Streams.size()) && (stream == NULL); i++ ) 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; return (uint32)(m - 'A')+1;
} }