From 52d7524ce047cd16192bb83bea15d36a90bb2a9f Mon Sep 17 00:00:00 2001
From: Christian Heller <c.heller@plomlompom.de>
Date: Thu, 23 Jan 2014 00:37:35 +0100
Subject: [PATCH] Removed memory leak in client's reset_windows(). (Previously,
 not all Win structs were freed; only those visible.)

---
 src/client/misc.c       |  9 +++++++--
 src/client/wincontrol.c | 33 +++++++++++++++------------------
 src/client/wincontrol.h |  3 +++
 3 files changed, 25 insertions(+), 20 deletions(-)

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.
  */
-- 
2.30.2