aboutsummaryrefslogtreecommitdiff
path: root/src/game/WaypointManager.cpp
diff options
context:
space:
mode:
authorMachiavelli <none@none>2009-08-22 16:54:14 +0200
committerMachiavelli <none@none>2009-08-22 16:54:14 +0200
commite0c660d831eeae3d3405a884f010861da2f92a5c (patch)
tree29a5a13b8db38b9ce8ddceb92b1446e323c5a7fc /src/game/WaypointManager.cpp
parent6ac8fcf4890f667b87ea7c26e606c551eb688c9e (diff)
* Fix memory leak in WaypointStore::UpdatePath
* Correct packet size calculating mistake from 5292 * Code style cleanup in Level2.cpp (Waypoint commands) --HG-- branch : trunk
Diffstat (limited to 'src/game/WaypointManager.cpp')
-rw-r--r--src/game/WaypointManager.cpp20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/game/WaypointManager.cpp b/src/game/WaypointManager.cpp
index 382f70a19ad..3ebbef7fc87 100644
--- a/src/game/WaypointManager.cpp
+++ b/src/game/WaypointManager.cpp
@@ -99,10 +99,17 @@ void WaypointStore::Load()
void WaypointStore::UpdatePath(uint32 id)
{
- // TODO: this will cause memory leak
- if(WaypointPathHolder.find(id) != WaypointPathHolder.end())
- WaypointPathHolder[id]->clear();
-
+ // Prevent memory leak, deallocate allocated memory instead of just clearing from object holder
+ WaypointPathMap::iterator itr = WaypointPathHolder.find(id);
+ if(itr != WaypointPathHolder.end())
+ {
+ for(WaypointPath::iterator jtr = WaypointPathHolder[id]->begin(); jtr != WaypointPathHolder[id]->end(); ++jtr)
+ {
+ delete (*jtr);
+ }
+ delete itr->second;
+ }
+
QueryResult *result;
result = WorldDatabase.PQuery("SELECT `id`,`point`,`position_x`,`position_y`,`position_z`,`move_flag`,`delay`,`action`,`action_chance` FROM `waypoint_data` WHERE id = %u ORDER BY `point`", id);
@@ -111,9 +118,7 @@ void WaypointStore::UpdatePath(uint32 id)
return;
WaypointPath* path_data;
-
path_data = new WaypointPath;
-
Field *fields;
do
@@ -142,7 +147,8 @@ void WaypointStore::UpdatePath(uint32 id)
path_data->push_back(wp);
- }while (result->NextRow());
+ }
+ while (result->NextRow());
WaypointPathHolder[id] = path_data;