From c70e2ccfc2a4abb277d32a66cc13c9229a07e6a8 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Thu, 7 Jan 2021 15:12:44 -0500 Subject: [PATCH] Must notify before waiting in destructor. Fix leaks --- src/zm_packetqueue.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/zm_packetqueue.cpp b/src/zm_packetqueue.cpp index 64679feef..7020de564 100644 --- a/src/zm_packetqueue.cpp +++ b/src/zm_packetqueue.cpp @@ -43,6 +43,9 @@ zm_packetqueue::zm_packetqueue( zm_packetqueue::~zm_packetqueue() { deleting = true; + + // Anyone waiting should immediately check deleting + condition.notify_all(); /* zma might be waiting. Must have exclusive access */ while ( !mutex.try_lock() ) { Debug(4, "Waiting for exclusive access"); @@ -85,7 +88,7 @@ bool zm_packetqueue::queuePacket(ZMPacket* add_packet) { packetqueue_iterator *iterator_it = *iterators_it; // Have to check each iterator and make sure it doesn't point to the packet we are about to delete if ( *iterator_it == pktQueue.end() ) { - Debug(4, "pointing it to back"); + Debug(4, "pointing it %p to back", iterator_it); --(*iterator_it); } } // end foreach iterator @@ -119,6 +122,7 @@ bool zm_packetqueue::queuePacket(ZMPacket* add_packet) { } if ( !zm_packet->trylock() ) { + Debug(1, "Have locked packet %d", zm_packet->image_index); video_stream_packets = max_video_packet_count; break; } @@ -137,10 +141,13 @@ bool zm_packetqueue::queuePacket(ZMPacket* add_packet) { } } // end foreach iterator - } while ( video_stream_packets < max_video_packet_count ); - + } while ( *it != add_packet ); + Debug(1, "Resulting video_stream_packets count %d, %d > %d, pointing at latet packet %d", video_stream_packets, + packet_counts[video_stream_id] - video_stream_packets, max_video_packet_count, + ( *it == add_packet ) + ); if ( - max_video_packet_count - video_stream_packets > max_video_packet_count + packet_counts[video_stream_id] - video_stream_packets > max_video_packet_count and ( *it != add_packet ) ) {