From 1872b8ed64328ebafec56b0888fa48f60fb4942b Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Sat, 31 Aug 2013 15:46:12 +0200 Subject: [PATCH] Fixed bug that freed non-existing map objects, triggered segfaults. --- src/map_objects.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/map_objects.c b/src/map_objects.c index 28d9b14..d220556 100644 --- a/src/map_objects.c +++ b/src/map_objects.c @@ -308,10 +308,11 @@ extern void * build_map_objects(struct World * world, void * start, char def_id, extern void free_items(struct Item * item) { - if (0 != item->map_obj.next) + if (0 == item) { - free_items((struct Item *) item->map_obj.next); + return; } + free_items((struct Item *) item->map_obj.next); free(item); } @@ -319,10 +320,11 @@ extern void free_items(struct Item * item) extern void free_monsters(struct Monster * monster) { - if (0 != monster->map_obj.next) + if (0 == monster) { - free_monsters((struct Monster *) monster->map_obj.next); + return; } + free_monsters((struct Monster *) monster->map_obj.next); free(monster); } -- 2.30.2