From 55dd8f87260b78cf0d7b861a222965ed97dc09b7 Mon Sep 17 00:00:00 2001 From: Richard Stanway Date: Mon, 12 Oct 2015 22:41:18 +0200 Subject: [PATCH] obs-ffmpeg: Fix a race condition in create_or_fetch_log_context Another thread could be manipulating the active_log_contexts array while the current thread is trying to read it, resulting in an uninitialized memory crash as the da_push_back call was not protected by the mutex. --- plugins/obs-ffmpeg/obs-ffmpeg.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/obs-ffmpeg/obs-ffmpeg.c b/plugins/obs-ffmpeg/obs-ffmpeg.c index 36b179a7c..761833447 100644 --- a/plugins/obs-ffmpeg/obs-ffmpeg.c +++ b/plugins/obs-ffmpeg/obs-ffmpeg.c @@ -36,7 +36,6 @@ static struct log_context *create_or_fetch_log_context(void *context) new_log_context = cached_log_contexts.array[cnt - 1]; da_pop_back(cached_log_contexts); } - pthread_mutex_unlock(&log_contexts_mutex); if (!new_log_context) new_log_context = bzalloc(sizeof(struct log_context)); @@ -47,6 +46,8 @@ static struct log_context *create_or_fetch_log_context(void *context) da_push_back(active_log_contexts, &new_log_context); + pthread_mutex_unlock(&log_contexts_mutex); + return new_log_context; } @@ -141,4 +142,4 @@ void obs_module_unload(void) da_free(active_log_contexts); da_free(cached_log_contexts); -} \ No newline at end of file +}