From 6b8cc14723024bbdcc8c3eca8785b8c39c58bd9a Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Mon, 31 Jan 2022 12:07:09 -0500 Subject: [PATCH] Don't free image data if we added the packet to an event. The lock moves to the event so it's not safe --- src/zm_monitor.cpp | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/src/zm_monitor.cpp b/src/zm_monitor.cpp index b55d2f91d..2c56ec6fe 100644 --- a/src/zm_monitor.cpp +++ b/src/zm_monitor.cpp @@ -2270,24 +2270,6 @@ bool Monitor::Analyse() { shared_data->state = state = IDLE; } // end if ( trigger_data->trigger_state != TRIGGER_OFF ) - if (event) event->AddPacket(packet_lock); - - // In the case where people have pre-alarm frames, the web ui will generate the frame images - // from the mp4. So no one will notice anyways. - if (snap->image and (videowriter == PASSTHROUGH)) { - if (!savejpegs) { - Debug(1, "Deleting image data for %d", snap->image_index); - // Don't need raw images anymore - delete snap->image; - snap->image = nullptr; - } - if (snap->analysis_image and !(savejpegs & 2)) { - Debug(1, "Deleting analysis image data for %d", snap->image_index); - delete snap->analysis_image; - snap->analysis_image = nullptr; - } - } - packetqueue.clearPackets(snap); if (snap->codec_type == AVMEDIA_TYPE_VIDEO) { @@ -2295,9 +2277,30 @@ bool Monitor::Analyse() { shared_data->last_read_index = snap->image_index; analysis_image_count++; } - packetqueue.increment_it(analysis_it); - if (!event) delete packet_lock; + + if (event) { + event->AddPacket(packet_lock); + } else { + // In the case where people have pre-alarm frames, the web ui will generate the frame images + // from the mp4. So no one will notice anyways. + if (snap->image and (videowriter == PASSTHROUGH)) { + if (!savejpegs) { + Debug(1, "Deleting image data for %d", snap->image_index); + // Don't need raw images anymore + delete snap->image; + snap->image = nullptr; + } + if (snap->analysis_image and !(savejpegs & 2)) { + Debug(1, "Deleting analysis image data for %d", snap->image_index); + delete snap->analysis_image; + snap->analysis_image = nullptr; + } + } + delete packet_lock; + } } // end scope for event_lock + + packetqueue.increment_it(analysis_it); //packetqueue.unlock(packet_lock); shared_data->last_read_time = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());