From 16b4cbfca1386757a6d4a1fc6a38300c23df846a Mon Sep 17 00:00:00 2001 From: Aleos Date: Thu, 6 May 2021 15:48:17 -0400 Subject: [PATCH] Resolves players warping to freed maps (#5922) * Fixes #4363. * Resolves players warping to freed maps resulting in a crash. * Clear out the instance_id from mapdata when clearing. Thanks to everyone who reported and helped get to the bottom of the issue! --- src/map/map.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/map/map.cpp b/src/map/map.cpp index 11f1f9c00c0..5313dcd2e8c 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -336,6 +336,9 @@ int map_addblock(struct block_list* bl) struct map_data *mapdata = map_getmapdata(m); + if (mapdata->cell == nullptr) // Player warped to a freed map. Stop them! + return 1; + if( x < 0 || x >= mapdata->xs || y < 0 || y >= mapdata->ys ) { ShowError("map_addblock: out-of-bounds coordinates (\"%s\",%d,%d), map is %dx%d\n", mapdata->name, x, y, mapdata->xs, mapdata->ys); @@ -2838,22 +2841,24 @@ int map_delinstancemap(int m) // Free memory if (mapdata->cell) aFree(mapdata->cell); - mapdata->cell = NULL; + mapdata->cell = nullptr; if (mapdata->block) aFree(mapdata->block); - mapdata->block = NULL; + mapdata->block = nullptr; if (mapdata->block_mob) aFree(mapdata->block_mob); - mapdata->block_mob = NULL; + mapdata->block_mob = nullptr; map_free_questinfo(mapdata); mapdata->damage_adjust = {}; mapdata->flag.clear(); mapdata->skill_damage.clear(); + mapdata->instance_id = 0; mapindex_removemap(mapdata->index); map_removemapdb(mapdata); + mapdata->index = 0; memset(&mapdata->name, '\0', sizeof(map[0].name)); // just remove the name return 1; }