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!
This commit is contained in:
Aleos
2021-05-06 15:48:17 -04:00
committed by GitHub
parent 60b1b514d4
commit 16b4cbfca1

View File

@@ -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;
}