Don't free image data if we added the packet to an event. The lock moves to the event so it's not safe

This commit is contained in:
Isaac Connor 2022-01-31 12:07:09 -05:00
parent b00ca5ce91
commit 6b8cc14723
1 changed files with 23 additions and 20 deletions

View File

@ -2270,8 +2270,17 @@ bool Monitor::Analyse() {
shared_data->state = state = IDLE;
} // end if ( trigger_data->trigger_state != TRIGGER_OFF )
if (event) event->AddPacket(packet_lock);
packetqueue.clearPackets(snap);
if (snap->codec_type == AVMEDIA_TYPE_VIDEO) {
// Only do these if it's a video packet.
shared_data->last_read_index = snap->image_index;
analysis_image_count++;
}
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)) {
@ -2287,17 +2296,11 @@ bool Monitor::Analyse() {
snap->analysis_image = nullptr;
}
}
packetqueue.clearPackets(snap);
if (snap->codec_type == AVMEDIA_TYPE_VIDEO) {
// Only do these if it's a video packet.
shared_data->last_read_index = snap->image_index;
analysis_image_count++;
delete packet_lock;
}
packetqueue.increment_it(analysis_it);
if (!event) 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());