diff options
author | Shauren <shauren.trinity@gmail.com> | 2013-08-26 17:38:02 +0200 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2013-08-26 17:38:02 +0200 |
commit | 4f44cdf2b5e2b4c5e695ea0929a51f692d8b7f2b (patch) | |
tree | afd645caf130514cd9942722b300c4d6dd2ad438 /src | |
parent | 664ed816dfc46a3e6be5fafa8037a8bd93feee5b (diff) |
Core/Scripts: Fixed uninitialized variable and memory leaks
Diffstat (limited to 'src')
4 files changed, 26 insertions, 15 deletions
diff --git a/src/server/game/Scripting/ScriptMgr.cpp b/src/server/game/Scripting/ScriptMgr.cpp index 0dc96b3dfd9..7c70ed5a737 100644 --- a/src/server/game/Scripting/ScriptMgr.cpp +++ b/src/server/game/Scripting/ScriptMgr.cpp @@ -33,6 +33,12 @@ #include "Player.h" #include "WorldPacket.h" +namespace +{ + typedef std::set<ScriptObject*> ExampleScriptContainer; + ExampleScriptContainer ExampleScripts; +} + // This is the global static registry of scripts. template<class TScript> class ScriptRegistry @@ -104,6 +110,9 @@ class ScriptRegistry if (script->GetName().find("example") == std::string::npos && script->GetName().find("Smart") == std::string::npos) TC_LOG_ERROR(LOG_FILTER_SQL, "Script named '%s' does not have a script name assigned in database.", script->GetName().c_str()); + + // These scripts don't get stored anywhere so throw them into this to avoid leaking memory + ExampleScripts.insert(script); } } else @@ -160,7 +169,11 @@ class ScriptRegistry if (!V) \ return R; - +struct TSpellSummary +{ + uint8 Targets; // set of enum SelectTarget + uint8 Effects; // set of enum SelectEffect +} *SpellSummary; ScriptMgr::ScriptMgr() : _scriptCount(0), _scheduledScripts(0) @@ -220,6 +233,13 @@ void ScriptMgr::Unload() SCR_CLEAR(UnitScript); #undef SCR_CLEAR + + for (ExampleScriptContainer::iterator itr = ExampleScripts.begin(); itr != ExampleScripts.end(); ++itr) + delete *itr; + ExampleScripts.clear(); + + delete[] SpellSummary; + delete[] UnitAI::AISpellInfo; } void ScriptMgr::LoadDatabase() @@ -227,14 +247,10 @@ void ScriptMgr::LoadDatabase() sScriptSystemMgr->LoadScriptWaypoints(); } -struct TSpellSummary -{ - uint8 Targets; // set of enum SelectTarget - uint8 Effects; // set of enum SelectEffect -} *SpellSummary; - void ScriptMgr::FillSpellSummary() { + UnitAI::FillAISpellInfo(); + SpellSummary = new TSpellSummary[sSpellMgr->GetSpellInfoStoreSize()]; SpellInfo const* pTempSpell; diff --git a/src/server/game/Spells/SpellMgr.cpp b/src/server/game/Spells/SpellMgr.cpp index e42d0f40998..5d471492553 100644 --- a/src/server/game/Spells/SpellMgr.cpp +++ b/src/server/game/Spells/SpellMgr.cpp @@ -27,7 +27,6 @@ #include "Chat.h" #include "Spell.h" #include "BattlegroundMgr.h" -#include "CreatureAI.h" #include "MapManager.h" #include "BattlefieldWG.h" #include "BattlefieldMgr.h" @@ -3001,8 +3000,6 @@ void SpellMgr::LoadSpellInfoCustomAttributes() spellInfo->_InitializeExplicitTargetMask(); } - CreatureAI::FillAISpellInfo(); - TC_LOG_INFO(LOG_FILTER_SERVER_LOADING, ">> Loaded SpellInfo custom attributes in %u ms", GetMSTimeDiffToNow(oldMSTime)); } diff --git a/src/server/scripts/EasternKingdoms/Karazhan/boss_prince_malchezaar.cpp b/src/server/scripts/EasternKingdoms/Karazhan/boss_prince_malchezaar.cpp index fffd6be8e9b..8f292f2d008 100644 --- a/src/server/scripts/EasternKingdoms/Karazhan/boss_prince_malchezaar.cpp +++ b/src/server/scripts/EasternKingdoms/Karazhan/boss_prince_malchezaar.cpp @@ -364,10 +364,8 @@ public: me->GetRandomNearPosition(pos, 60); else { - std::vector<InfernalPoint*>::iterator itr = positions.begin()+rand()%positions.size(); - point = *itr; - positions.erase(itr); - pos.Relocate(point->x, point->y, INFERNAL_Z, 0.0f); + point = Trinity::Containers::SelectRandomContainerElement(positions); + pos.Relocate(point->x, point->y, INFERNAL_Z, frand(0.0f, float(M_PI * 2))); } Creature* infernal = me->SummonCreature(NETHERSPITE_INFERNAL, pos, TEMPSUMMON_TIMED_DESPAWN, 180000); diff --git a/src/server/scripts/Northrend/IcecrownCitadel/boss_valithria_dreamwalker.cpp b/src/server/scripts/Northrend/IcecrownCitadel/boss_valithria_dreamwalker.cpp index 557d6768790..bbd700b7edd 100644 --- a/src/server/scripts/Northrend/IcecrownCitadel/boss_valithria_dreamwalker.cpp +++ b/src/server/scripts/Northrend/IcecrownCitadel/boss_valithria_dreamwalker.cpp @@ -493,7 +493,7 @@ class npc_green_dragon_combat_trigger : public CreatureScript struct npc_green_dragon_combat_triggerAI : public BossAI { - npc_green_dragon_combat_triggerAI(Creature* creature) : BossAI(creature, DATA_VALITHRIA_DREAMWALKER) + npc_green_dragon_combat_triggerAI(Creature* creature) : BossAI(creature, DATA_VALITHRIA_DREAMWALKER), _evadeCheck(false) { } |