Skip to content

Commit

Permalink
Resolves players warping to freed maps (#5922)
Browse files Browse the repository at this point in the history
* 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!
  • Loading branch information
aleos89 committed May 6, 2021
1 parent 60b1b51 commit 16b4cbf
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/map/map.cpp
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 16b4cbf

Please sign in to comment.