Browse Source

libobs: Prevent access to OBS context during shutdown

The "obs" global variable can still be accessed by functions during
shutdown.  To prevent access to the variable during shutdown, move the
pointer to a temporary function variable, and set the "obs" global
variable to NULL before shutting down.
jp9000 8 years ago
parent
commit
f06f85fd56
1 changed files with 14 additions and 11 deletions
  1. 14 11
      libobs/obs.c

+ 14 - 11
libobs/obs.c

@@ -810,6 +810,7 @@ bool obs_startup(const char *locale, const char *module_config_path,
 void obs_shutdown(void)
 void obs_shutdown(void)
 {
 {
 	struct obs_module *module;
 	struct obs_module *module;
+	struct obs_core *core;
 
 
 	if (!obs)
 	if (!obs)
 		return;
 		return;
@@ -850,25 +851,27 @@ void obs_shutdown(void)
 	obs->procs = NULL;
 	obs->procs = NULL;
 	obs->signals = NULL;
 	obs->signals = NULL;
 
 
-	module = obs->first_module;
+	core = obs;
+	obs = NULL;
+
+	module = core->first_module;
 	while (module) {
 	while (module) {
 		struct obs_module *next = module->next;
 		struct obs_module *next = module->next;
 		free_module(module);
 		free_module(module);
 		module = next;
 		module = next;
 	}
 	}
-	obs->first_module = NULL;
+	core->first_module = NULL;
 
 
-	for (size_t i = 0; i < obs->module_paths.num; i++)
-		free_module_path(obs->module_paths.array+i);
-	da_free(obs->module_paths);
+	for (size_t i = 0; i < core->module_paths.num; i++)
+		free_module_path(core->module_paths.array+i);
+	da_free(core->module_paths);
 
 
-	if (obs->name_store_owned)
-		profiler_name_store_free(obs->name_store);
+	if (core->name_store_owned)
+		profiler_name_store_free(core->name_store);
 
 
-	bfree(obs->module_config_path);
-	bfree(obs->locale);
-	bfree(obs);
-	obs = NULL;
+	bfree(core->module_config_path);
+	bfree(core->locale);
+	bfree(core);
 
 
 #ifdef _WIN32
 #ifdef _WIN32
 	uninitialize_com();
 	uninitialize_com();