Files
TrinityCore/src/game/WaypointManager.h
Anubisss cdb7b3227b 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
2010-05-13 00:42:37 +02:00

69 lines
1.9 KiB
C++

/*
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
*
* Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef TRINITY_WAYPOINTMANAGER_H
#define TRINITY_WAYPOINTMANAGER_H
#include <ace/Singleton.h>
#include <ace/Null_Mutex.h>
#include <vector>
struct WaypointData
{
uint32 id;
float x,y,z;
bool run;
uint32 delay;
uint32 event_id;
uint8 event_chance;
};
typedef std::vector<WaypointData*> WaypointPath;
class WaypointStore
{
private :
uint32 records;
UNORDERED_MAP<uint32, WaypointPath*> waypoint_map;
public:
// 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();
WaypointPath* GetPath(uint32 id)
{
if (waypoint_map.find(id) != waypoint_map.end())
return waypoint_map[id];
else return 0;
}
inline uint32 GetRecordsCount() { return records; }
};
#define sWaypointMgr WaypointStore::instance()
#endif