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
This commit is contained in:
jp9000 2021-12-14 10:28:00 -08:00
parent 1f20e0ca93
commit b2c09d3523

View File

@ -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);
if (cur_source)
obs_source_video_tick(cur_source, seconds);
source = (struct obs_source *)source->context.next;
if (cur_source) {
obs_source_video_tick(cur_source, seconds);
if (cur_source)
obs_source_release(cur_source);
}
}
pthread_mutex_unlock(&data->sources_mutex);