fix: move sendFrame inside mutex scope to prevent race condition

sendFrame() reads frames[curr_frame_id-1] but was called outside the
mutex scope. The command processor thread (running processCommand via
checkCommandQueue) can modify curr_frame_id or reload the event
(clearing/rebuilding frames) between the mutex unlock and the
sendFrame call, causing out-of-bounds access.

Move sendFrame into the first mutex scope so frames[] access is
protected from concurrent modification by the command thread.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Nic Boet
2026-02-08 22:37:40 -06:00
parent 011defdad2
commit 328d5c2a99

View File

@@ -1079,22 +1079,18 @@ void EventStream::runStream() {
continue;
} // end if !in_event
} // end scope for mutex lock
if (send_frame) {
if (!sendFrame(delta)) {
zm_terminate = true;
break;
if (send_frame) {
if (!sendFrame(delta)) {
zm_terminate = true;
break;
}
if (send_twice and !sendFrame(delta)) {
zm_terminate = true;
break;
}
frame_count++;
}
if (send_twice and !sendFrame(delta)) {
zm_terminate = true;
break;
}
frame_count++;
}
{
std::scoped_lock lck{mutex};
if (!paused && !event_data->frames.empty()
&& curr_frame_id >= 1 && curr_frame_id <= (int)event_data->frames.size()) {