mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-26 18:35:20 +00:00
Fix memory leaks
This commit is contained in:
parent
abcfe9bcee
commit
14e1911820
@ -91,6 +91,8 @@ std::list<AiPackage*>::const_iterator AiSequence::erase(std::list<AiPackage*>::c
|
|||||||
{
|
{
|
||||||
if (package == it)
|
if (package == it)
|
||||||
{
|
{
|
||||||
|
AiPackage* package = *it;
|
||||||
|
delete package;
|
||||||
return mPackages.erase(it);
|
return mPackages.erase(it);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -125,7 +127,10 @@ void AiSequence::stopCombat()
|
|||||||
for(std::list<AiPackage*>::iterator it = mPackages.begin(); it != mPackages.end(); )
|
for(std::list<AiPackage*>::iterator it = mPackages.begin(); it != mPackages.end(); )
|
||||||
{
|
{
|
||||||
if ((*it)->getTypeId() == AiPackage::TypeIdCombat)
|
if ((*it)->getTypeId() == AiPackage::TypeIdCombat)
|
||||||
|
{
|
||||||
|
delete *it;
|
||||||
it = mPackages.erase(it);
|
it = mPackages.erase(it);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
@ -136,7 +141,10 @@ void AiSequence::stopPursuit()
|
|||||||
for(std::list<AiPackage*>::iterator it = mPackages.begin(); it != mPackages.end(); )
|
for(std::list<AiPackage*>::iterator it = mPackages.begin(); it != mPackages.end(); )
|
||||||
{
|
{
|
||||||
if ((*it)->getTypeId() == AiPackage::TypeIdPursue)
|
if ((*it)->getTypeId() == AiPackage::TypeIdPursue)
|
||||||
|
{
|
||||||
|
delete *it;
|
||||||
it = mPackages.erase(it);
|
it = mPackages.erase(it);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
@ -268,7 +276,10 @@ void AiSequence::stack (const AiPackage& package, const MWWorld::Ptr& actor)
|
|||||||
for(std::list<AiPackage *>::iterator it = mPackages.begin(); it != mPackages.end();)
|
for(std::list<AiPackage *>::iterator it = mPackages.begin(); it != mPackages.end();)
|
||||||
{
|
{
|
||||||
if((*it)->canCancel())
|
if((*it)->canCancel())
|
||||||
|
{
|
||||||
|
delete *it;
|
||||||
it = mPackages.erase(it);
|
it = mPackages.erase(it);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
@ -349,49 +360,49 @@ void AiSequence::readState(const ESM::AiSequence::AiSequence &sequence)
|
|||||||
for (std::vector<ESM::AiSequence::AiPackageContainer>::const_iterator it = sequence.mPackages.begin();
|
for (std::vector<ESM::AiSequence::AiPackageContainer>::const_iterator it = sequence.mPackages.begin();
|
||||||
it != sequence.mPackages.end(); ++it)
|
it != sequence.mPackages.end(); ++it)
|
||||||
{
|
{
|
||||||
MWMechanics::AiPackage* package = NULL;
|
std::auto_ptr<MWMechanics::AiPackage> package (NULL);
|
||||||
switch (it->mType)
|
switch (it->mType)
|
||||||
{
|
{
|
||||||
case ESM::AiSequence::Ai_Wander:
|
case ESM::AiSequence::Ai_Wander:
|
||||||
{
|
{
|
||||||
package = new AiWander(static_cast<ESM::AiSequence::AiWander*>(it->mPackage));
|
package.reset(new AiWander(static_cast<ESM::AiSequence::AiWander*>(it->mPackage)));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ESM::AiSequence::Ai_Travel:
|
case ESM::AiSequence::Ai_Travel:
|
||||||
{
|
{
|
||||||
package = new AiTravel(static_cast<ESM::AiSequence::AiTravel*>(it->mPackage));
|
package.reset(new AiTravel(static_cast<ESM::AiSequence::AiTravel*>(it->mPackage)));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ESM::AiSequence::Ai_Escort:
|
case ESM::AiSequence::Ai_Escort:
|
||||||
{
|
{
|
||||||
package = new AiEscort(static_cast<ESM::AiSequence::AiEscort*>(it->mPackage));
|
package.reset(new AiEscort(static_cast<ESM::AiSequence::AiEscort*>(it->mPackage)));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ESM::AiSequence::Ai_Follow:
|
case ESM::AiSequence::Ai_Follow:
|
||||||
{
|
{
|
||||||
package = new AiFollow(static_cast<ESM::AiSequence::AiFollow*>(it->mPackage));
|
package.reset(new AiFollow(static_cast<ESM::AiSequence::AiFollow*>(it->mPackage)));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ESM::AiSequence::Ai_Activate:
|
case ESM::AiSequence::Ai_Activate:
|
||||||
{
|
{
|
||||||
package = new AiActivate(static_cast<ESM::AiSequence::AiActivate*>(it->mPackage));
|
package.reset(new AiActivate(static_cast<ESM::AiSequence::AiActivate*>(it->mPackage)));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ESM::AiSequence::Ai_Combat:
|
case ESM::AiSequence::Ai_Combat:
|
||||||
{
|
{
|
||||||
package = new AiCombat(static_cast<ESM::AiSequence::AiCombat*>(it->mPackage));
|
package.reset(new AiCombat(static_cast<ESM::AiSequence::AiCombat*>(it->mPackage)));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ESM::AiSequence::Ai_Pursue:
|
case ESM::AiSequence::Ai_Pursue:
|
||||||
{
|
{
|
||||||
package = new AiPursue(static_cast<ESM::AiSequence::AiPursue*>(it->mPackage));
|
package.reset(new AiPursue(static_cast<ESM::AiSequence::AiPursue*>(it->mPackage)));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!package)
|
if (!package.get())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// remove previous packages if required
|
// remove previous packages if required
|
||||||
@ -400,13 +411,16 @@ void AiSequence::readState(const ESM::AiSequence::AiSequence &sequence)
|
|||||||
for(std::list<AiPackage *>::iterator it = mPackages.begin(); it != mPackages.end();)
|
for(std::list<AiPackage *>::iterator it = mPackages.begin(); it != mPackages.end();)
|
||||||
{
|
{
|
||||||
if((*it)->canCancel())
|
if((*it)->canCancel())
|
||||||
|
{
|
||||||
|
delete *it;
|
||||||
it = mPackages.erase(it);
|
it = mPackages.erase(it);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mPackages.push_back(package);
|
mPackages.push_back(package.release());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user