diff --git a/cheats.c b/cheats.c index b18d39b87f..f49388d3f5 100644 --- a/cheats.c +++ b/cheats.c @@ -169,24 +169,25 @@ bool cheat_manager_save(const char *path) return ret; } -cheat_manager_t *cheat_manager_load(const char *path) +bool cheat_manager_load(const char *path) { unsigned cheats = 0, i; - cheat_manager_t *cheat = NULL; - config_file_t *conf = config_file_new(path); + cheat_manager_t *cheat; + config_file_t *conf = config_file_new(path); + global_t *global = global_get_ptr(); if (!conf) - return NULL; + return false; config_get_uint(conf, "cheats", &cheats); if (cheats == 0) - return NULL; + return false; cheat = cheat_manager_new(cheats); if (!cheat) - return NULL; + return false; for (i = 0; i < cheats; i++) { @@ -217,7 +218,9 @@ cheat_manager_t *cheat_manager_load(const char *path) config_file_free(conf); - return cheat; + global->cheat = cheat; + + return true; } cheat_manager_t *cheat_manager_new(unsigned size) @@ -288,8 +291,10 @@ bool cheat_manager_realloc(unsigned new_size) return true; } -void cheat_manager_free(cheat_manager_t *handle) +void cheat_manager_free(void) { + global_t *global = global_get_ptr(); + cheat_manager_t *handle = global->cheat; if (!handle) return; @@ -409,9 +414,10 @@ void cheat_manager_state_checks( void cheat_manager_state_free(void) { - global_t *global = global_get_ptr(); + global_t *global; + cheat_manager_free(); + + global = global_get_ptr(); - if (global->cheat) - cheat_manager_free(global->cheat); global->cheat = NULL; } diff --git a/cheats.h b/cheats.h index 515b517050..331e174905 100644 --- a/cheats.h +++ b/cheats.h @@ -29,7 +29,7 @@ unsigned cheat_manager_get_size(void); cheat_manager_t *cheat_manager_new(unsigned size); -cheat_manager_t *cheat_manager_load(const char *path); +bool cheat_manager_load(const char *path); /** * cheat_manager_save: @@ -45,7 +45,7 @@ bool cheat_manager_realloc(unsigned new_size); void cheat_manager_set_code(unsigned index, const char *str); -void cheat_manager_free(cheat_manager_t *handle); +void cheat_manager_free(void); void cheat_manager_index_next(cheat_manager_t *handle); diff --git a/menu/cbs/menu_cbs_ok.c b/menu/cbs/menu_cbs_ok.c index b0e09ce4a1..7aae066ed9 100644 --- a/menu/cbs/menu_cbs_ok.c +++ b/menu/cbs/menu_cbs_ok.c @@ -713,12 +713,9 @@ static int generic_action_ok(const char *path, } break; case ACTION_OK_LOAD_CHEAT_FILE: - if (global->cheat) - cheat_manager_free(global->cheat); + cheat_manager_free(); - global->cheat = cheat_manager_load(action_path); - - if (!global->cheat) + if (!cheat_manager_load(action_path)) goto error; break; case ACTION_OK_APPEND_DISK_IMAGE: