From: Christian Heller Date: Thu, 29 Aug 2013 23:54:40 +0000 (+0200) Subject: Clean up memory allocated for Win structs. X-Git-Tag: tce~999 X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/te"st.html?a=commitdiff_plain;h=c0a785104a8081e7911647345285da9e9ed22907;p=plomrogue Clean up memory allocated for Win structs. --- diff --git a/src/main.c b/src/main.c index bd25c4f..566a660 100644 --- a/src/main.c +++ b/src/main.c @@ -205,13 +205,18 @@ int main(int argc, char *argv[]) exit_err(init_win_meta(screen, &win_meta), &world, err_winmem); world.wins.meta = &win_meta; struct Win win_keys = init_win_from_file(&world, "Keys", draw_keys_win); + world.wins.keys = &win_keys; + set_cleanup_flag(CLEANUP_WIN_KEYS); struct Win win_info = init_win_from_file(&world, "Info", draw_info_win); + world.wins.info = &win_info; + set_cleanup_flag(CLEANUP_WIN_INFO); struct Win win_log = init_win_from_file(&world, "Log", draw_log_win); - struct Win win_map = init_win_from_file(&world, "Map", draw_map_win); - world.wins.keys = &win_keys; world.wins.log = &win_log; - world.wins.info = &win_info; + set_cleanup_flag(CLEANUP_WIN_LOG); + struct Win win_map = init_win_from_file(&world, "Map", draw_map_win); world.wins.map = &win_map; + set_cleanup_flag(CLEANUP_WIN_MAP); + sorted_wintoggle(&world); /* Replay mode. */ diff --git a/src/rexit.c b/src/rexit.c index 2497c03..7bd4440 100644 --- a/src/rexit.c +++ b/src/rexit.c @@ -10,11 +10,12 @@ #include "map.h" /* for Map struct */ #include "keybindings.h" /* for KeysWinData, KeyBinding structs */ #include "command_db.h" /* for free_command_db() */ +#include "windows.h" /* for Win struct */ /* The clean-up routine and the flag resource by which it decides what to do. */ -static uint8_t cleanup_flags = 0x00; +static uint32_t cleanup_flags = 0x0000; static void cleanup(struct World * world); @@ -47,6 +48,22 @@ static void cleanup(struct World * world) { free_command_db(world); } + if (cleanup_flags & CLEANUP_WIN_INFO) + { + free(world->wins.info->_title); + } + if (cleanup_flags & CLEANUP_WIN_MAP) + { + free(world->wins.map->_title); + } + if (cleanup_flags & CLEANUP_WIN_LOG) + { + free(world->wins.log->_title); + } + if (cleanup_flags & CLEANUP_WIN_KEYS) + { + free(world->wins.keys->_title); + } } diff --git a/src/rexit.h b/src/rexit.h index fcb7155..3ba34c4 100644 --- a/src/rexit.h +++ b/src/rexit.h @@ -21,11 +21,15 @@ struct Map; */ enum cleanup_flag { - CLEANUP_NCURSES = 0x01, - CLEANUP_MAP = 0x02, - CLEANUP_KEYBINDINGS = 0x04, - CLEANUP_LOG = 0x08, - CLEANUP_COMMAND_DB = 0x10 + CLEANUP_NCURSES = 0x0001, + CLEANUP_MAP = 0x0002, + CLEANUP_KEYBINDINGS = 0x0004, + CLEANUP_LOG = 0x0008, + CLEANUP_COMMAND_DB = 0x0010, + CLEANUP_WIN_INFO = 0x0020, + CLEANUP_WIN_LOG = 0x0040, + CLEANUP_WIN_MAP = 0x0080, + CLEANUP_WIN_KEYS = 0x0100 }; extern void set_cleanup_flag(enum cleanup_flag flag);