summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorglx <glx@openttd.org>2007-01-25 01:29:24 +0000
committerglx <glx@openttd.org>2007-01-25 01:29:24 +0000
commit35de25eec1cbf5a61d151251c499b899c273e24d (patch)
treedb0d09f651b2be5265eaaa6461ba27ddadb3b414 /src
parent9727bb4cfc954b5ecf18a3cf81cbc8c541b14d7d (diff)
downloadopenttd-35de25eec1cbf5a61d151251c499b899c273e24d.tar.xz
(svn r8399) -Fix (r8185): a new road stop was always created in CmdBuildRoadStop(), but it was not deleted if DC_EXEC flag was not set or if the station creation failed
Diffstat (limited to 'src')
-rw-r--r--src/station_cmd.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp
index b73211dd7..e5924cbd8 100644
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -1359,12 +1359,19 @@ int32 CmdBuildRoadStop(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
if (st != NULL && st->facilities != 0) st = NULL;
}
+ /* If DC_EXEC is NOT set we still need to create the road stop to test if everything is OK.
+ * In this case we need to delete it before return. */
+ std::auto_ptr<RoadStop> rs_auto_delete;
+
//give us a road stop in the list, and check if something went wrong
road_stop = new RoadStop(tile);
if (road_stop == NULL) {
return_cmd_error(type ? STR_3008B_TOO_MANY_TRUCK_STOPS : STR_3008A_TOO_MANY_BUS_STOPS);
}
+ /* ensure that in case of error (or no DC_EXEC) the new road stop gets deleted upon return */
+ rs_auto_delete = std::auto_ptr<RoadStop>(road_stop);
+
if (st != NULL &&
GetNumRoadStopsInStation(st, RS_BUS) + GetNumRoadStopsInStation(st, RS_TRUCK) >= ROAD_STOP_LIMIT) {
return_cmd_error(type ? STR_3008B_TOO_MANY_TRUCK_STOPS : STR_3008A_TOO_MANY_BUS_STOPS);
@@ -1421,8 +1428,9 @@ int32 CmdBuildRoadStop(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
UpdateStationAcceptance(st, false);
RebuildStationLists();
InvalidateWindow(WC_STATION_LIST, st->owner);
- /* success, so don't delete the new station */
+ /* success, so don't delete the new station and the new road stop */
st_auto_delete.release();
+ rs_auto_delete.release();
}
return cost;
}