From fc26e3cfcfc0bef5cefa60a72933f800401ddf41 Mon Sep 17 00:00:00 2001 From: sorayuki Date: Fri, 9 Mar 2018 15:50:23 +0800 Subject: [PATCH] libobs: Fix potential filter rendering race condition The filters array should not be accessed without locking the filter mutex. This locks the filter mutex, grabs a reference to the first filter, unlocks the mutex, renders the filter, and then releases the reference. Closes obsproject/obs-studio#1215 --- libobs/obs-source.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/libobs/obs-source.c b/libobs/obs-source.c index 869711738..6dcdcc55c 100644 --- a/libobs/obs-source.c +++ b/libobs/obs-source.c @@ -1720,9 +1720,18 @@ static inline void obs_source_render_async_video(obs_source_t *source) static inline void obs_source_render_filters(obs_source_t *source) { + obs_source_t *first_filter; + + pthread_mutex_lock(&source->filter_mutex); + first_filter = source->filters.array[0]; + obs_source_addref(first_filter); + pthread_mutex_unlock(&source->filter_mutex); + source->rendering_filter = true; - obs_source_video_render(source->filters.array[0]); + obs_source_video_render(first_filter); source->rendering_filter = false; + + obs_source_release(first_filter); } void obs_source_default_render(obs_source_t *source)