From 533c5c0eb11785db9ce23fa6edd317f9a3a43613 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sat, 21 Mar 2015 01:53:14 +0100 Subject: [PATCH] Create rarch_main_global_init/rarch_main_global_deinit --- retroarch.c | 13 ------------- runloop.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/retroarch.c b/retroarch.c index 997d7626a7..ddcc875f5a 100644 --- a/retroarch.c +++ b/retroarch.c @@ -1638,24 +1638,11 @@ static void free_temporary_content(void) /* main_clear_state_extern: * * Clears all external state. - * - * XXX This memset is really dangerous. - * - * (a) it can leak memory because the pointers - * in g_extern aren't freed. - * (b) it can zero pointers that the rest of - * the code will look at. */ static void main_clear_state_extern(void) { - rarch_main_command(RARCH_CMD_TEMPORARY_CONTENT_DEINIT); - rarch_main_command(RARCH_CMD_SUBSYSTEM_FULLPATHS_DEINIT); - rarch_main_command(RARCH_CMD_RECORD_DEINIT); - rarch_main_command(RARCH_CMD_LOG_FILE_DEINIT); rarch_main_command(RARCH_CMD_HISTORY_DEINIT); - memset(&g_extern, 0, sizeof(g_extern)); - rarch_main_clear_state(); rarch_main_data_clear_state(); } diff --git a/runloop.c b/runloop.c index 7d8ab31429..e7b32289c3 100644 --- a/runloop.c +++ b/runloop.c @@ -982,6 +982,32 @@ static void rarch_main_state_deinit(void) free(runloop); } +static void rarch_main_global_deinit(void) +{ + rarch_main_command(RARCH_CMD_TEMPORARY_CONTENT_DEINIT); + rarch_main_command(RARCH_CMD_SUBSYSTEM_FULLPATHS_DEINIT); + rarch_main_command(RARCH_CMD_RECORD_DEINIT); + rarch_main_command(RARCH_CMD_LOG_FILE_DEINIT); + +#if 0 + global_t *global = &g_extern; + + if (!global) + return; + + free(global); +#endif +} + +static void rarch_main_global_init(void) +{ +#if 0 + g_extern = rarch_main_global_init(); +#else + memset(&g_extern, 0, sizeof(g_extern)); +#endif +} + static runloop_t *rarch_main_state_init(void) { runloop_t *runloop = (runloop_t*)calloc(1, sizeof(runloop_t)); @@ -996,6 +1022,9 @@ void rarch_main_clear_state(void) { rarch_main_state_deinit(); g_runloop = rarch_main_state_init(); + + rarch_main_global_deinit(); + rarch_main_global_init(); } bool rarch_main_is_idle(void)