浏览代码

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.
Richard Stanway 10 年之前
父节点
当前提交
55dd8f8726
共有 1 个文件被更改,包括 3 次插入2 次删除
  1. 3 2
      plugins/obs-ffmpeg/obs-ffmpeg.c

+ 3 - 2
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];
 		new_log_context = cached_log_contexts.array[cnt - 1];
 		da_pop_back(cached_log_contexts);
 		da_pop_back(cached_log_contexts);
 	}
 	}
-	pthread_mutex_unlock(&log_contexts_mutex);
 
 
 	if (!new_log_context)
 	if (!new_log_context)
 		new_log_context = bzalloc(sizeof(struct 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);
 	da_push_back(active_log_contexts, &new_log_context);
 
 
+	pthread_mutex_unlock(&log_contexts_mutex);
+
 	return new_log_context;
 	return new_log_context;
 }
 }
 
 
@@ -141,4 +142,4 @@ void obs_module_unload(void)
 
 
 	da_free(active_log_contexts);
 	da_free(active_log_contexts);
 	da_free(cached_log_contexts);
 	da_free(cached_log_contexts);
-}
+}