Turn cheat_manager_free into static function

This commit is contained in:
twinaphex 2019-09-17 01:20:30 +02:00
parent d526530167
commit 4ea493c86c
3 changed files with 46 additions and 50 deletions

View File

@ -270,6 +270,51 @@ bool cheat_manager_copy_working_to_idx(unsigned idx)
return true;
}
static void cheat_manager_free(void)
{
unsigned i = 0;
if (cheat_manager_state.cheats)
{
for (i = 0; i < cheat_manager_state.size; i++)
{
if (cheat_manager_state.cheats[i].desc)
free(cheat_manager_state.cheats[i].desc);
if (cheat_manager_state.cheats[i].code)
free(cheat_manager_state.cheats[i].code);
}
free(cheat_manager_state.cheats);
}
if (cheat_manager_state.prev_memory_buf)
free(cheat_manager_state.prev_memory_buf);
if (cheat_manager_state.matches)
free(cheat_manager_state.matches);
if (cheat_manager_state.memory_buf_list)
free(cheat_manager_state.memory_buf_list);
if (cheat_manager_state.memory_size_list)
free(cheat_manager_state.memory_size_list);
cheat_manager_state.cheats = NULL;
cheat_manager_state.size = 0;
cheat_manager_state.buf_size = 0;
cheat_manager_state.prev_memory_buf = NULL;
cheat_manager_state.curr_memory_buf = NULL;
cheat_manager_state.memory_buf_list = NULL;
cheat_manager_state.memory_size_list = NULL;
cheat_manager_state.matches = NULL;
cheat_manager_state.num_memory_buffers = 0;
cheat_manager_state.total_memory_size = 0;
cheat_manager_state.memory_initialized = false;
cheat_manager_state.memory_search_initialized = false;
}
static void cheat_manager_new(unsigned size)
{
unsigned i;
@ -518,50 +563,6 @@ bool cheat_manager_realloc(unsigned new_size, unsigned default_handler)
return true;
}
void cheat_manager_free(void)
{
unsigned i = 0;
if (cheat_manager_state.cheats)
{
for (i = 0; i < cheat_manager_state.size; i++)
{
if (cheat_manager_state.cheats[i].desc)
free(cheat_manager_state.cheats[i].desc);
if (cheat_manager_state.cheats[i].code)
free(cheat_manager_state.cheats[i].code);
}
free(cheat_manager_state.cheats);
}
if (cheat_manager_state.prev_memory_buf)
free(cheat_manager_state.prev_memory_buf);
if (cheat_manager_state.matches)
free(cheat_manager_state.matches);
if (cheat_manager_state.memory_buf_list)
free(cheat_manager_state.memory_buf_list);
if (cheat_manager_state.memory_size_list)
free(cheat_manager_state.memory_size_list);
cheat_manager_state.cheats = NULL;
cheat_manager_state.size = 0;
cheat_manager_state.buf_size = 0;
cheat_manager_state.prev_memory_buf = NULL;
cheat_manager_state.curr_memory_buf = NULL;
cheat_manager_state.memory_buf_list = NULL;
cheat_manager_state.memory_size_list = NULL;
cheat_manager_state.matches = NULL;
cheat_manager_state.num_memory_buffers = 0;
cheat_manager_state.total_memory_size = 0;
cheat_manager_state.memory_initialized = false;
cheat_manager_state.memory_search_initialized = false;
}
void cheat_manager_update(cheat_manager_t *handle, unsigned handle_idx)
{
char msg[256];

View File

@ -207,8 +207,6 @@ bool cheat_manager_realloc(unsigned new_size, unsigned default_handler);
void cheat_manager_set_code(unsigned index, const char *str);
void cheat_manager_free(void);
void cheat_manager_index_next(void);
void cheat_manager_index_prev(void);

View File

@ -1659,16 +1659,13 @@ static int generic_action_ok(const char *path,
break;
case ACTION_OK_LOAD_CHEAT_FILE:
flush_char = msg_hash_to_str(flush_id);
cheat_manager_free();
cheat_manager_state_free();
if (!cheat_manager_load(action_path,false))
goto error;
break;
case ACTION_OK_LOAD_CHEAT_FILE_APPEND:
flush_char = msg_hash_to_str(flush_id);
#if 0
cheat_manager_free();
#endif
if (!cheat_manager_load(action_path,true))
goto error;