home · contact · privacy
At clean-up, free memory of map object definitions, too.
authorChristian Heller <c.heller@plomlompom.de>
Fri, 30 Aug 2013 23:48:01 +0000 (01:48 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Fri, 30 Aug 2013 23:48:01 +0000 (01:48 +0200)
src/main.c
src/map_objects.c
src/map_objects.h
src/rexit.c
src/rexit.h

index 0ecc10a3dec4b3aa30233cc52df1ffe2e430e595..9b752090be053bad9b7ae978772d947025543ea5 100644 (file)
@@ -103,6 +103,8 @@ int main(int argc, char *argv[])
     world.monster = 0;
     world.item = 0;
     init_map_object_defs(&world, "config/defs");
+    set_cleanup_flag(CLEANUP_MAP_OBJECT_DEFS);
+    exit_err(1, &world, NULL);
 
     /* For interactive mode, try to load world state from savefile. */
     char * err_o = "Trouble loading game (fopen() in main()) / "
index e35a88c49c01b692e10ea14998dc40d27d1cc591..4cd6cb0d8cae2a682196861a18e8a3292d3cd615 100644 (file)
@@ -139,6 +139,31 @@ extern void init_map_object_defs(struct World * world, char * filename)
 
 
 
+extern void free_item_defs(struct ItemDef * id_start)
+{
+    if (0 != id_start->map_obj_def.next)
+    {
+        free_item_defs((struct ItemDef *) id_start->map_obj_def.next);
+    }
+    free(id_start->map_obj_def.desc);
+    free(id_start);
+}
+
+
+
+
+extern void free_monster_defs(struct MonsterDef * md_start)
+{
+    if (0 != md_start->map_obj_def.next)
+    {
+        free_monster_defs((struct MonsterDef *) md_start->map_obj_def.next);
+    }
+    free(md_start->map_obj_def.desc);
+    free(md_start);
+}
+
+
+
 extern uint8_t write_map_objects(struct World * world, void * start,
                                  FILE * file)
 {
index 4804033d1002fe17499242046fdd5ff804d12f30..83ae7c5c610553097bb2684736abffbacb94777c 100644 (file)
@@ -79,6 +79,14 @@ extern void init_map_object_defs(struct World * world, char * filename);
 
 
 
+/* Free item / monster definitions in map object chain starting at "md_start" /
+ * "id_start".
+ */
+extern void free_item_defs(struct ItemDef * id_start);
+extern void free_monster_defs(struct MonsterDef * md_start);
+
+
+
 /* Build into memory starting at "start" chain of "n" map objects of type
  * "def_id".
  */
index 85e2bfc328798fdb3085bfa9676118084073176a..e0d029f124b1d6218c2dde85e8b3167cd371aa12 100644 (file)
@@ -11,6 +11,7 @@
 #include "keybindings.h" /* for KeysWinData, KeyBinding structs */
 #include "command_db.h" /* for free_command_db() */
 #include "windows.h" /* for Win struct, free_win() */
+#include "map_objects.h" /* for free_item_defs(), free_monster_defs() */
 
 
 
@@ -64,6 +65,11 @@ static void cleanup(struct World * world)
     {
         free_win(world->wins.keys);
     }
+    if (cleanup_flags & CLEANUP_MAP_OBJECT_DEFS)
+    {
+        free_item_defs(world->item_def);
+        free_monster_defs(world->monster_def);
+    }
 }
 
 
index 3ba34c4b976488ea723420c87ed355c15a602a5e..6336788ddf8c19012cdea8cbc771517de834f7bc 100644 (file)
@@ -21,15 +21,16 @@ struct Map;
  */
 enum cleanup_flag
 {
-    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
+    CLEANUP_NCURSES         = 0x0001,
+    CLEANUP_MAP             = 0x0002,
+    CLEANUP_KEYBINDINGS     = 0x0004,
+    CLEANUP_LOG             = 0x0008,
+    CLEANUP_COMMAND_DB      = 0x0010,
+    CLEANUP_MAP_OBJECT_DEFS = 0x0020,
+    CLEANUP_WIN_INFO        = 0x0040,
+    CLEANUP_WIN_LOG         = 0x0080,
+    CLEANUP_WIN_MAP         = 0x0100,
+    CLEANUP_WIN_KEYS        = 0x0200
 };
 extern void set_cleanup_flag(enum cleanup_flag flag);