Fix heap use after free when removing oil rig
This commit is contained in:
@@ -143,6 +143,8 @@ Industry::~Industry()
|
|||||||
* Also we must not decrement industry counts in that case. */
|
* Also we must not decrement industry counts in that case. */
|
||||||
if (this->location.w == 0) return;
|
if (this->location.w == 0) return;
|
||||||
|
|
||||||
|
const bool has_neutral_station = this->neutral_station != nullptr;
|
||||||
|
|
||||||
TILE_AREA_LOOP(tile_cur, this->location) {
|
TILE_AREA_LOOP(tile_cur, this->location) {
|
||||||
if (IsTileType(tile_cur, MP_INDUSTRY)) {
|
if (IsTileType(tile_cur, MP_INDUSTRY)) {
|
||||||
if (GetIndustryIndex(tile_cur) == this->index) {
|
if (GetIndustryIndex(tile_cur) == this->index) {
|
||||||
@@ -156,7 +158,7 @@ Industry::~Industry()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this->neutral_station != nullptr) {
|
if (has_neutral_station) {
|
||||||
/* Remove possible docking tiles */
|
/* Remove possible docking tiles */
|
||||||
TILE_AREA_LOOP(tile_cur, this->location) {
|
TILE_AREA_LOOP(tile_cur, this->location) {
|
||||||
ClearDockingTilesCheckingNeighbours(tile_cur);
|
ClearDockingTilesCheckingNeighbours(tile_cur);
|
||||||
|
@@ -4390,6 +4390,10 @@ void DeleteOilRig(TileIndex tile)
|
|||||||
MakeWaterKeepingClass(tile, OWNER_NONE);
|
MakeWaterKeepingClass(tile, OWNER_NONE);
|
||||||
|
|
||||||
assert(st->facilities == (FACIL_AIRPORT | FACIL_DOCK) && st->airport.type == AT_OILRIG);
|
assert(st->facilities == (FACIL_AIRPORT | FACIL_DOCK) && st->airport.type == AT_OILRIG);
|
||||||
|
if (st->industry != nullptr && st->industry->neutral_station == st) {
|
||||||
|
/* Don't leave dangling neutral station pointer */
|
||||||
|
st->industry->neutral_station = nullptr;
|
||||||
|
}
|
||||||
delete st;
|
delete st;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user