Browse Source

libobs: Fix potentially unsafe linked list traversal

Fixes an issue pointed out in obsproject/obs-browser#333 where a source
may destroy the next source in obs_source_video_tick(), thus
invalidating the next source in the linked list. Get the next source in
the list *after* calling obs_source_video_tick() rather than before.

Closes obsproject/obs-studio#5600
jp9000 3 years ago
parent
commit
b2c09d3523
1 changed files with 5 additions and 3 deletions
  1. 5 3
      libobs/obs-video.c

+ 5 - 3
libobs/obs-video.c

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