From cdb7b3227b0c021806d4edd16e26b6f8355dc2e2 Mon Sep 17 00:00:00 2001 From: Anubisss Date: Thu, 13 May 2010 00:42:37 +0200 Subject: Call WaypointMgr's Free() in its destructor. Deallocate memory in Free() which allocated by WaypointMgr. This fixes memory leaks caused by waypoints. Valgrind log: ==31592== 2,203,488 (59,400 direct, 2,144,088 indirect) bytes in 2,475 blocks are definitely lost in loss record 1,230 of 1,232 ==31592== at 0x4C2626C: operator new(unsigned long) (vg_replace_malloc.c:230) ==31592== by 0xD0EC23: WaypointStore::Load() (WaypointManager.cpp:70) ==31592== by 0xD1B55D: World::SetInitialWorldSettings() (World.cpp:1565) ==31592== by 0x90F34E: Master::Run() (Master.cpp:234) ==31592== by 0x90E87E: main (Main.cpp:146) ==31592== ==31592== ==31592== 160 bytes in 5 blocks are possibly lost in loss record 10 of 1,232 ==31592== at 0x4C2626C: operator new(unsigned long) (vg_replace_malloc.c:230) ==31592== by 0xD0EC0D: WaypointStore::Load() (WaypointManager.cpp:67) ==31592== by 0xD1B55D: World::SetInitialWorldSettings() (World.cpp:1565) ==31592== by 0x90F34E: Master::Run() (Master.cpp:234) ==31592== by 0x90E87E: main (Main.cpp:146) ==31592== ==31592== ==31592== 384 bytes in 2 blocks are possibly lost in loss record 285 of 1,232 ==31592== at 0x4C2626C: operator new(unsigned long) (vg_replace_malloc.c:230) ==31592== by 0xD0F2D4: __gnu_cxx::new_allocator::allocate(unsigned long, void const*) (new_allocator.h:92) ==31592== by 0xD0F303: std::_Vector_base >::_M_allocate(unsigned long) (stl_vector.h:144) ==31592== by 0xD0F87B: std::vector >::_M_insert_aux(__gnu_cxx::__normal_iterator > >, WaypointData* const&) (vector.tcc:308) ==31592== by 0xD0F9F7: std::vector >::push_back(WaypointData* const&) (stl_vector.h:694) ==31592== by 0xD0ED0B: WaypointStore::Load() (WaypointManager.cpp:89) ==31592== by 0xD1B55D: World::SetInitialWorldSettings() (World.cpp:1565) ==31592== by 0x90F34E: Master::Run() (Master.cpp:234) ==31592== by 0x90E87E: main (Main.cpp:146) --HG-- branch : trunk --- src/game/WaypointManager.cpp | 6 ++++++ src/game/WaypointManager.h | 1 + 2 files changed, 7 insertions(+) (limited to 'src/game') diff --git a/src/game/WaypointManager.cpp b/src/game/WaypointManager.cpp index bd052306992..9bdd8c93734 100644 --- a/src/game/WaypointManager.cpp +++ b/src/game/WaypointManager.cpp @@ -26,6 +26,12 @@ void WaypointStore::Free() { + for (UNORDERED_MAP::const_iterator itr = waypoint_map.begin(); itr != waypoint_map.end(); ++itr) + { + for (WaypointPath::const_iterator it = itr->second->begin(); it != itr->second->end(); ++it) + delete *it; + delete itr->second; + } waypoint_map.clear(); } diff --git a/src/game/WaypointManager.h b/src/game/WaypointManager.h index b70d07a9b9b..7efca558146 100644 --- a/src/game/WaypointManager.h +++ b/src/game/WaypointManager.h @@ -47,6 +47,7 @@ class WaypointStore // Null Mutex is OK because WaypointMgr is initialized in the World thread before World is initialized static WaypointStore* instance() { return ACE_Singleton::instance(); } + ~WaypointStore() { Free(); } void UpdatePath(uint32 id); void Load(); void Free(); -- cgit v1.2.3