Przeglądaj źródła

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
sorayuki 7 lat temu
rodzic
commit
fc26e3cfcf
1 zmienionych plików z 10 dodań i 1 usunięć
  1. 10 1
      libobs/obs-source.c

+ 10 - 1
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)