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<WaypointData*>::allocate(unsigned long, void const*) (new_allocator.h:92)
==31592==    by 0xD0F303: std::_Vector_base<WaypointData*, std::allocator<WaypointData*> >::_M_allocate(unsigned long) (stl_vector.h:144)
==31592==    by 0xD0F87B: std::vector<WaypointData*, std::allocator<WaypointData*> >::_M_insert_aux(__gnu_cxx::__normal_iterator<WaypointData**, std::vector<WaypointData*, std::allocator<WaypointData*> > >, WaypointData* const&) (vector.tcc:308)
==31592==    by 0xD0F9F7: std::vector<WaypointData*, std::allocator<WaypointData*> >::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
This commit is contained in:
Anubisss
2010-05-13 00:42:37 +02:00
parent 5d70f62c07
commit cdb7b3227b
2 changed files with 7 additions and 0 deletions

View File

@@ -26,6 +26,12 @@
void WaypointStore::Free()
{
for (UNORDERED_MAP<uint32, WaypointPath*>::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();
}

View File

@@ -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<WaypointStore, ACE_Null_Mutex>::instance(); }
~WaypointStore() { Free(); }
void UpdatePath(uint32 id);
void Load();
void Free();