From: Christian Heller Date: Wed, 22 Jan 2014 23:37:35 +0000 (+0100) Subject: Removed memory leak in client's reset_windows(). (Previously, not all Win X-Git-Tag: tce~873 X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/%7B%7B%20web_path%20%7D%7D/%7B%7Bdb.prefix%7D%7D/task?a=commitdiff_plain;h=52d7524ce047cd16192bb83bea15d36a90bb2a9f;p=plomrogue Removed memory leak in client's reset_windows(). (Previously, not all Win structs were freed; only those visible.) --- diff --git a/src/client/misc.c b/src/client/misc.c index 7022c6f..01cf1d2 100644 --- a/src/client/misc.c +++ b/src/client/misc.c @@ -11,7 +11,8 @@ #include "map_window.h" /* for map_center() */ #include "wincontrol.h" /* struct WinConf, init_winconfs(), init_wins(), * sorted_wintoggle_and_activate(), get_win_by_id(), - * get_winconf_by_win(), toggle_window() + * get_winconf_by_win(), toggle_window(), + * get_next_winconf_id() */ #include "windows.h" /* struct Win, make_pad(), suspend_win(), free_win() */ #include "world.h" /* global world */ @@ -86,7 +87,11 @@ extern void reset_windows() { w_p = world.wmeta.active; suspend_win(w_p); - free_win(w_p); + } + char id; + while (0 != (id = get_next_winconf_id())) + { + free_win(get_win_by_id(id)); } delwin(world.wmeta.pad); make_pad(); diff --git a/src/client/wincontrol.c b/src/client/wincontrol.c index 5e818ba..01b9be8 100644 --- a/src/client/wincontrol.c +++ b/src/client/wincontrol.c @@ -56,9 +56,6 @@ static struct WinConf * get_winconf_by_id(char id); /* Get (Win->draw) function identified by "c"; NULL if c not mapped to one. */ static void * get_drawfunc_by_char(char c); -/* Iterate over chars of world.winconf_db.winconf_ids array. Restart after \0.*/ -static char get_next_winconf_id(); - static char * string_prefixed_id(char * prefix, char id) @@ -287,21 +284,6 @@ static void * get_drawfunc_by_char(char c) -static char get_next_winconf_id() -{ - static uint8_t i = 0; - char c = world.winconf_db.winconf_ids[i]; - if (0 == c) - { - i = 0; - return c; - } - i++; - return c; -} - - - extern struct WinConf * get_winconf_by_win(struct Win * win) { uint8_t i = 0; @@ -428,6 +410,21 @@ extern void sorted_wintoggle_and_activate() +extern char get_next_winconf_id() +{ + static uint8_t i = 0; + char c = world.winconf_db.winconf_ids[i]; + if (0 == c) + { + i = 0; + return c; + } + i++; + return c; +} + + + extern void save_win_configs() { char * f_name = "save_win_configs()"; diff --git a/src/client/wincontrol.h b/src/client/wincontrol.h index 778e34f..e025cce 100644 --- a/src/client/wincontrol.h +++ b/src/client/wincontrol.h @@ -59,6 +59,9 @@ extern void init_wins(); */ extern void sorted_wintoggle_and_activate(); +/* Iterate over chars of world.winconf_db.winconf_ids array. Restart after \0.*/ +extern char get_next_winconf_id(); + /* Save world.winconfs, visible window chain and active window selection to the * respective configuration files in client config windows directory. */