Fix memory leaks in ConditionManager.
--HG-- branch : trunk
This commit is contained in:
@@ -201,6 +201,7 @@ ConditionMgr::ConditionMgr()
|
||||
|
||||
ConditionMgr::~ConditionMgr()
|
||||
{
|
||||
Clean();
|
||||
}
|
||||
|
||||
ConditionList ConditionMgr::GetConditionReferences(uint32 refId)
|
||||
@@ -287,8 +288,8 @@ ConditionList ConditionMgr::GetConditionsForNotGroupedEntry(ConditionSourceType
|
||||
|
||||
void ConditionMgr::LoadConditions(bool isReload)
|
||||
{
|
||||
m_ConditionMap.clear(); // for reload case
|
||||
m_ConditionReferenceMap.clear(); // for reload case
|
||||
Clean();
|
||||
|
||||
//must clear all custom handled cases (groupped types) before reload
|
||||
if (isReload)
|
||||
{
|
||||
@@ -354,6 +355,7 @@ void ConditionMgr::LoadConditions(bool isReload)
|
||||
if (iConditionTypeOrReference == iSourceTypeOrReferenceId)//self referencing, skip
|
||||
{
|
||||
sLog.outErrorDb("Condition reference %i is referencing self, skipped", iSourceTypeOrReferenceId);
|
||||
delete cond;
|
||||
continue;
|
||||
}
|
||||
cond->mReferenceId = uint32(abs(iConditionTypeOrReference));
|
||||
@@ -373,8 +375,10 @@ void ConditionMgr::LoadConditions(bool isReload)
|
||||
if (cond->mSourceEntry && iSourceTypeOrReferenceId < 0)
|
||||
sLog.outErrorDb("Condition %s %i has useless data in SourceEntry (%u)!", rowType, iSourceTypeOrReferenceId, cond->mSourceEntry);
|
||||
}else if (!isConditionTypeValid(cond))//doesn't have reference, validate ConditionType
|
||||
{
|
||||
delete cond;
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
if (iSourceTypeOrReferenceId < 0)//it is a reference template
|
||||
{
|
||||
@@ -393,12 +397,16 @@ void ConditionMgr::LoadConditions(bool isReload)
|
||||
|
||||
//if not a reference and SourceType is invalid, skip
|
||||
if (iConditionTypeOrReference >= 0 && !isSourceTypeValid(cond))
|
||||
{
|
||||
delete cond;
|
||||
continue;
|
||||
}
|
||||
|
||||
//Grouping is only allowed for some types (loot templates, gossip menus, gossip items)
|
||||
if (cond->mSourceGroup && !isGroupable(cond->mSourceType))
|
||||
{
|
||||
sLog.outErrorDb("Condition type %u has not allowed grouping %u!", uint32(cond->mSourceType), cond->mSourceGroup);
|
||||
delete cond;
|
||||
continue;
|
||||
}else if (cond->mSourceGroup)
|
||||
{
|
||||
@@ -450,9 +458,15 @@ void ConditionMgr::LoadConditions(bool isReload)
|
||||
break;
|
||||
}
|
||||
if (!bIsDone)
|
||||
{
|
||||
sLog.outErrorDb("Not handled grouped condition, SourceGroup %u", cond->mSourceGroup);
|
||||
delete cond;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_AllocatedMemory.push_back(cond);
|
||||
++count;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1143,3 +1157,31 @@ bool ConditionMgr::isConditionTypeValid(Condition* cond)
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void ConditionMgr::Clean()
|
||||
{
|
||||
for (ConditionReferenceMap::iterator itr = m_ConditionReferenceMap.begin(); itr != m_ConditionReferenceMap.end(); ++itr)
|
||||
{
|
||||
for (ConditionList::const_iterator it = itr->second.begin(); it != itr->second.end(); ++it)
|
||||
delete *it;
|
||||
itr->second.clear();
|
||||
}
|
||||
m_ConditionReferenceMap.clear();
|
||||
|
||||
for (ConditionMap::iterator itr = m_ConditionMap.begin(); itr != m_ConditionMap.end(); ++itr)
|
||||
{
|
||||
for (ConditionTypeMap::iterator it = itr->second.begin(); it != itr->second.end(); ++it)
|
||||
{
|
||||
for (ConditionList::const_iterator i = it->second.begin(); i != it->second.end(); ++i)
|
||||
delete *i;
|
||||
it->second.clear();
|
||||
}
|
||||
itr->second.clear();
|
||||
}
|
||||
m_ConditionMap.clear();
|
||||
|
||||
// this is a BIG hack, feel free to fix it if you can figure out the ConditionMgr ;)
|
||||
for (std::list<Condition*>::const_iterator itr = m_AllocatedMemory.begin(); itr != m_AllocatedMemory.end(); ++itr)
|
||||
delete *itr;
|
||||
m_AllocatedMemory.clear();
|
||||
}
|
||||
|
||||
@@ -160,6 +160,9 @@ class ConditionMgr
|
||||
sourceType == CONDITION_SOURCE_TYPE_GOSSIP_MENU ||
|
||||
sourceType == CONDITION_SOURCE_TYPE_GOSSIP_MENU_OPTION);
|
||||
}
|
||||
|
||||
void Clean(); // free up resources
|
||||
std::list<Condition*> m_AllocatedMemory; // some garbage collection :)
|
||||
};
|
||||
|
||||
#define sConditionMgr Trinity::Singleton<ConditionMgr>::Instance()
|
||||
|
||||
Reference in New Issue
Block a user