From 87c536ebe0b0703c6709bf0b5ae0c8bca8409277 Mon Sep 17 00:00:00 2001 From: Richard Stanway Date: Wed, 8 Sep 2021 22:52:39 +0200 Subject: [PATCH] image-source: Use mutex when accessing slideshow While adding or updating files locked this mutex, the graphics thread did not. As the update operation is not atomic, the graphics thread might access the darray in the middle of an update, resulting in access to freed memory (crash) if the files were updated at the same time. --- plugins/image-source/obs-slideshow.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/plugins/image-source/obs-slideshow.c b/plugins/image-source/obs-slideshow.c index 53b11af8d..352f4531f 100644 --- a/plugins/image-source/obs-slideshow.c +++ b/plugins/image-source/obs-slideshow.c @@ -738,8 +738,10 @@ static void ss_video_tick(void *data, float seconds) { struct slideshow *ss = data; + pthread_mutex_lock(&ss->mutex); + if (!ss->transition || !ss->slide_time) - return; + goto finish; if (ss->restart_on_activate && ss->use_cut) { ss->elapsed = 0.0f; @@ -748,11 +750,11 @@ static void ss_video_tick(void *data, float seconds) ss->restart_on_activate = false; ss->use_cut = false; ss->stop = false; - return; + goto finish; } if (ss->pause_on_deactivate || ss->manual || ss->stop || ss->paused) - return; + goto finish; /* ----------------------------------------------------- */ /* fade to transparency when the file list becomes empty */ @@ -779,11 +781,14 @@ static void ss_video_tick(void *data, float seconds) else do_transition(ss, false); - return; + goto finish; } obs_source_media_next(ss->source); } + +finish: + pthread_mutex_unlock(&ss->mutex); } static inline bool ss_audio_render_(obs_source_t *transition, uint64_t *ts_out,