Skip to content

Commit 9a3552a

Browse files
committed
vcap/file: fix locking
The fix commit 8c19440 (2025-10-01) locked in flush_capture_data(), which was ok when called from rewind_file(). But that function is called also from vidcap_file_process_message() which is called with mutex already held (CID 896223). So moving the lock from flush_captured_data() up to rewind_file(). Also CID 896221 is fixed - subsequent s->new_msg was called seemingly without lock (double lock + 1x unlock considered unlocked). Now in this context one pair lock/unlock was removed which means that the lock is still held. fixes CID 896221, CID 896223, commit 8c19440
1 parent 44848b6 commit 9a3552a

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/video_capture/file.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ static void vidcap_file_show_help(bool full) {
166166
}
167167
}
168168

169+
// s->lock must be held when calling this function
169170
static void flush_captured_data(struct vidcap_state_lavf_decoder *s) {
170-
pthread_mutex_lock(&s->lock);
171171
struct video_frame *f = NULL;
172172
while ((f = simple_linked_list_pop(s->video_frame_queue)) != NULL) {
173173
VIDEO_FRAME_DISPOSE(f);
@@ -185,7 +185,6 @@ static void flush_captured_data(struct vidcap_state_lavf_decoder *s) {
185185
avcodec_flush_buffers(s->aud_ctx);
186186
}
187187
s->audio_end_ts = AV_NOPTS_VALUE;
188-
pthread_mutex_unlock(&s->lock);
189188
}
190189

191190
static void vidcap_file_common_cleanup(struct vidcap_state_lavf_decoder *s) {
@@ -355,6 +354,7 @@ static void print_current_pos(struct vidcap_state_lavf_decoder *s,
355354
action_failed; \
356355
} \
357356
} while (0)
357+
// s->lock must be held when calling this function
358358
static void vidcap_file_process_messages(struct vidcap_state_lavf_decoder *s) {
359359
struct msg_universal *msg;
360360
while ((msg = (struct msg_universal *) check_message(&s->mod)) != NULL) {
@@ -493,7 +493,9 @@ rewind_file(struct vidcap_state_lavf_decoder *s)
493493
avio_seek(s->fmt_ctx->pb, s->video_stream_idx, SEEK_SET),
494494
{});
495495
}
496+
pthread_mutex_lock(&s->lock);
496497
flush_captured_data(s);
498+
pthread_mutex_unlock(&s->lock);
497499
}
498500

499501
#define FAIL_WORKER { pthread_mutex_lock(&s->lock); s->failed = true; pthread_mutex_unlock(&s->lock); pthread_cond_signal(&s->new_frame_ready); return NULL; }

0 commit comments

Comments
 (0)