home · contact · privacy
Fixed bug where record unlinking in remake_world() *always* unlinked *any* previously...
[plomrogue] / src / server / map_objects.c
index 648631e2723be79c8024fd85611cbee6f17ef494..36fb9b79829d9667f2f984f361fe77d6a62d72e7 100644 (file)
@@ -5,7 +5,7 @@
 #include <stdio.h> /* FILE typedef */
 #include <stdint.h> /* uint8_t, uint16_t */
 #include <stdlib.h> /* free(), atoi() */
-#include <string.h> /* strlen(), memcpy(), strtok() */
+#include <string.h> /* strlen(), memcpy(), strtok(), memset() */
 #include "../common/readwrite.h" /* try_fopen(), try_fclose(), try_fgets(),
                                   * textfile_sizes()
                                   */
@@ -67,6 +67,7 @@ static void add_map_object(uint8_t type)
     char * f_name = "add_map_object()";
     struct MapObjDef * mod = get_map_object_def(type);
     struct MapObj *    mo  = try_malloc(sizeof(struct MapObj), f_name);
+    memset(mo, 0, sizeof(struct MapObj));
     mo->id         = world.map_obj_count++;
     mo->type       = mod->id;
     mo->lifepoints = mod->lifepoints;
@@ -89,11 +90,6 @@ static void add_map_object(uint8_t type)
             break;
         }
     }
-    mo->progress = 0;
-    mo->command  = 0;
-    mo->arg      = 0;
-    mo->owns     = NULL;
-    mo->next     = NULL;
     struct MapObj ** mo_ptr_ptr = &world.map_objs;
     for (; NULL != * mo_ptr_ptr; mo_ptr_ptr = &(*mo_ptr_ptr)->next);
     * mo_ptr_ptr = mo;
@@ -138,7 +134,6 @@ extern void free_map_object_defs(struct MapObjDef * mod_start)
     free_map_object_defs(mod_start->next);
     free(mod_start->name);
     free(mod_start);
-    mod_start = NULL;
 }
 
 
@@ -163,10 +158,10 @@ extern void free_map_objects(struct MapObj * mo_start)
     free_map_objects(mo_start->owns);
     free_map_objects(mo_start->next);
     free(mo_start);
-    if (mo_start == world.map_objs)
-    {
-        world.map_objs = NULL;
-    }
+    if (mo_start == world.map_objs)  /* So add_map_objects()' NULL-delimited  */
+    {                                /* map object iteration loop does not    */
+        world.map_objs = NULL;       /* iterate over freed memory when called */
+    }                                /* the 1st time after world re-seeding.  */
 }