home · contact · privacy
Clean up memory allocated for Win structs.
authorChristian Heller <c.heller@plomlompom.de>
Thu, 29 Aug 2013 23:54:40 +0000 (01:54 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Thu, 29 Aug 2013 23:54:40 +0000 (01:54 +0200)
src/main.c
src/rexit.c
src/rexit.h

index bd25c4fcdd840244a72577ce78e9c912a11880bc..566a660ea29afb8de4bd22c8fccc7e22dfa71bc5 100644 (file)
@@ -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. */
index 2497c034014a6e3d6b585b9d6a9b306aa6cc41c8..7bd4440ab7d429607788a657c76f13e81916bcfc 100644 (file)
 #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);
+    }
 }
 
 
index fcb71559e11f3f1fc7fcfb6ca511640ec7b4690c..3ba34c4b976488ea723420c87ed355c15a602a5e 100644 (file)
@@ -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);