瀏覽代碼

libobs: Fix race conditions

Uses obs_source_get_ref on the sources enumerated in the tick_sources
function in obs-video.c to ensure a reference has been incremented
before calling that source's video_tick, and replaces an
obs_source_addref with obs_source_get_ref in the push_audio_tree
function in obs-audio.c to ensure that it cannot increment a source that
has already decremented its reference to 0.
jp9000 6 年之前
父節點
當前提交
573197af5b
共有 2 個文件被更改,包括 8 次插入3 次删除
  1. 2 2
      libobs/obs-audio.c
  2. 6 1
      libobs/obs-video.c

+ 2 - 2
libobs/obs-audio.c

@@ -31,8 +31,8 @@ static void push_audio_tree(obs_source_t *parent, obs_source_t *source, void *p)
 	struct obs_core_audio *audio = p;
 	struct obs_core_audio *audio = p;
 
 
 	if (da_find(audio->render_order, &source, 0) == DARRAY_INVALID) {
 	if (da_find(audio->render_order, &source, 0) == DARRAY_INVALID) {
-		obs_source_addref(source);
-		da_push_back(audio->render_order, &source);
+		obs_source_t *s = obs_source_get_ref(source);
+		if (s) da_push_back(audio->render_order, &s);
 	}
 	}
 
 
 	UNUSED_PARAMETER(parent);
 	UNUSED_PARAMETER(parent);

+ 6 - 1
libobs/obs-video.c

@@ -58,8 +58,13 @@ static uint64_t tick_sources(uint64_t cur_time, uint64_t last_time)
 
 
 	source = data->first_source;
 	source = data->first_source;
 	while (source) {
 	while (source) {
-		obs_source_video_tick(source, seconds);
+		struct obs_source *cur_source = obs_source_get_ref(source);
 		source = (struct obs_source*)source->context.next;
 		source = (struct obs_source*)source->context.next;
+
+		if (cur_source) {
+			obs_source_video_tick(cur_source, seconds);
+			obs_source_release(cur_source);
+		}
 	}
 	}
 
 
 	pthread_mutex_unlock(&data->sources_mutex);
 	pthread_mutex_unlock(&data->sources_mutex);