libobs: Fix a race condition when initializing audio sources

The source shouldn't be inserted into obs->data.first_audio_source until it's
fully initialized, or other threads will access source->control and
dereference an uninitialized pointer.
上级 a73b09c7
......@@ -166,6 +166,16 @@ bool obs_source_init(struct obs_source *source)
if (is_audio_source(source) || is_composite_source(source))
allocate_audio_output_buffer(source);
if (source->info.type == OBS_SOURCE_TYPE_TRANSITION) {
if (!obs_transition_init(source))
return false;
}
source->control = bzalloc(sizeof(obs_weak_source_t));
source->deinterlace_top_first = true;
source->control->source = source;
source->audio_mixers = 0xF;
if (is_audio_source(source)) {
pthread_mutex_lock(&obs->data.audio_sources_mutex);
......@@ -180,16 +190,6 @@ bool obs_source_init(struct obs_source *source)
pthread_mutex_unlock(&obs->data.audio_sources_mutex);
}
if (source->info.type == OBS_SOURCE_TYPE_TRANSITION) {
if (!obs_transition_init(source))
return false;
}
source->control = bzalloc(sizeof(obs_weak_source_t));
source->deinterlace_top_first = true;
source->control->source = source;
source->audio_mixers = 0xF;
obs_context_data_insert(&source->context,
&obs->data.sources_mutex,
&obs->data.first_source);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册