diff --git a/configuration.c b/configuration.c index d9b3ec572e..89738d988e 100644 --- a/configuration.c +++ b/configuration.c @@ -37,9 +37,56 @@ #include "config.h" #endif -static settings_t *g_config; struct defaults g_defaults; +static settings_t **config_get_ptr_double(void) +{ + static settings_t *g_config; + return &g_config; +} + +static void config_free_ptr(void) +{ + settings_t **settings = config_get_ptr_double(); + *settings = NULL; +} + +settings_t *config_get_ptr(void) +{ + settings_t **settings = config_get_ptr_double(); + return *settings; +} + +void config_free(void) +{ + settings_t *settings = config_get_ptr(); + if (!settings) + return; + + free(settings); + config_free_ptr(); +} + +static bool config_init(void) +{ + settings_t **settings = config_get_ptr_double(); + settings_t *config = (settings_t*)calloc(1, sizeof(settings_t)); + + if (!config) + return false; + + *settings = config; + + return true; +} + +bool config_realloc(void) +{ + config_free(); + return config_init(); +} + + /** * config_get_default_audio: * @@ -2857,26 +2904,3 @@ bool config_save_file(const char *path) return ret; } -settings_t *config_get_ptr(void) -{ - return g_config; -} - -void config_free(void) -{ - if (!g_config) - return; - - free(g_config); - g_config = NULL; -} - -settings_t *config_init(void) -{ - g_config = (settings_t*)calloc(1, sizeof(settings_t)); - - if (!g_config) - return NULL; - - return g_config; -} diff --git a/configuration.h b/configuration.h index 6d9be0a267..a632f39b7d 100644 --- a/configuration.h +++ b/configuration.h @@ -543,7 +543,7 @@ bool config_save_autoconf_profile(const char *path, unsigned user); **/ bool config_save_file(const char *path); -settings_t *config_init(void); +bool config_realloc(void); void config_free(void); diff --git a/retroarch.c b/retroarch.c index 1a07649393..a75462c2ae 100644 --- a/retroarch.c +++ b/retroarch.c @@ -1086,13 +1086,7 @@ static void main_init_state_config(void) void rarch_main_alloc(void) { - settings_t *settings = config_get_ptr(); - - if (settings) - config_free(); - settings = config_init(); - - if (!settings) + if (!config_realloc()) return; event_command(EVENT_CMD_HISTORY_DEINIT);