Skip to content

Commit

Permalink
Fix memleak
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberium authored and Fabi committed Jan 3, 2017
1 parent c9b2ed0 commit c6a5d70
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 10 deletions.
4 changes: 1 addition & 3 deletions src/game/Creature.cpp
Expand Up @@ -756,10 +756,8 @@ bool Creature::AIM_Initialize()
return false;
}*/

CreatureAI* oldAI = m_ai;
i_motionMaster.Initialize();
m_ai = FactorySelector::selectAI(this);
delete oldAI;
m_ai.reset(FactorySelector::selectAI(this));

// Handle Spawned Events, also calls Reset()
m_ai->JustRespawned();
Expand Down
5 changes: 3 additions & 2 deletions src/game/Creature.h
Expand Up @@ -26,6 +26,7 @@
#include "Cell.h"

#include <list>
#include <memory>

struct SpellEntry;

Expand Down Expand Up @@ -581,7 +582,7 @@ class MANGOS_DLL_SPEC Creature : public Unit

bool AIM_Initialize();

virtual CreatureAI* AI() override { if (m_charmInfo && m_charmInfo->GetAI()) return m_charmInfo->GetAI(); else return m_ai; }
virtual CreatureAI* AI() override { if (m_charmInfo && m_charmInfo->GetAI()) return m_charmInfo->GetAI(); else return m_ai.get(); }
virtual CombatData* GetCombatData() override { if (m_charmInfo && m_charmInfo->GetCombatData()) return m_charmInfo->GetCombatData(); else return m_combatData; }

void SetWalk(bool enable, bool asDefault = true);
Expand Down Expand Up @@ -800,7 +801,7 @@ class MANGOS_DLL_SPEC Creature : public Unit

Position m_respawnPos;

CreatureAI* m_ai;
std::unique_ptr<CreatureAI> m_ai;

private:
GridReference<Creature> m_gridRef;
Expand Down
4 changes: 0 additions & 4 deletions src/game/ObjectGridLoader.cpp
Expand Up @@ -267,10 +267,6 @@ template<class T>
void
ObjectGridUnloader::Visit(GridRefManager<T>& m)
{
// remove all cross-reference before deleting
for (typename GridRefManager<T>::iterator iter = m.begin(); iter != m.end(); ++iter)
iter->getSource()->CleanupsBeforeDelete();

while (!m.isEmpty())
{
T* obj = m.getFirst()->getSource();
Expand Down
2 changes: 1 addition & 1 deletion src/game/Pet.h
Expand Up @@ -262,7 +262,7 @@ class MANGOS_DLL_SPEC Pet : public Creature
bool m_removed; // prevent overwrite pet state in DB at next Pet::Update if pet already removed(saved)

// return charminfo ai only when this pet is possessed. (eye of the beast case for ex.)
virtual CreatureAI* AI() override { if (hasUnitState(UNIT_STAT_CONTROLLED) && m_charmInfo->GetAI()) return m_charmInfo->GetAI(); else return m_ai; }
virtual CreatureAI* AI() override { if (hasUnitState(UNIT_STAT_CONTROLLED) && m_charmInfo->GetAI()) return m_charmInfo->GetAI(); else return m_ai.get(); }
virtual CombatData* GetCombatData() override { return m_combatData; }

protected:
Expand Down

0 comments on commit c6a5d70

Please sign in to comment.