fix(Core/Pet): Fix possible crash when using dangling pointer as pets spell target and fix possible memory leak. (#21420)
This commit is contained in:
parent
47c524581b
commit
fe2627bc91
@ -47,7 +47,7 @@ Pet::Pet(Player* owner, PetType type) : Guardian(nullptr, owner ? owner->GetGUID
|
||||
m_auraRaidUpdateMask(0),
|
||||
m_loading(false),
|
||||
m_petRegenTimer(PET_FOCUS_REGEN_INTERVAL),
|
||||
m_tempspellTarget(nullptr),
|
||||
m_tempspellTarget(),
|
||||
m_tempoldTarget(),
|
||||
m_tempspellIsPositive(false),
|
||||
m_tempspell(0)
|
||||
@ -716,9 +716,11 @@ void Pet::Update(uint32 diff)
|
||||
|
||||
if (m_tempspell)
|
||||
{
|
||||
Unit* tempspellTarget = m_tempspellTarget;
|
||||
Unit* tempoldTarget = nullptr;
|
||||
Unit* tempspellTarget = nullptr;
|
||||
if (!m_tempspellTarget.IsEmpty())
|
||||
tempspellTarget = ObjectAccessor::GetUnit(*this, m_tempspellTarget);
|
||||
|
||||
Unit* tempoldTarget = nullptr;
|
||||
if (!m_tempoldTarget.IsEmpty())
|
||||
tempoldTarget = ObjectAccessor::GetUnit(*this, m_tempoldTarget);
|
||||
|
||||
@ -758,7 +760,7 @@ void Pet::Update(uint32 diff)
|
||||
|
||||
CastSpell(tempspellTarget, tempspell, false);
|
||||
m_tempspell = 0;
|
||||
m_tempspellTarget = nullptr;
|
||||
m_tempspellTarget = ObjectGuid::Empty;
|
||||
|
||||
if (tempspellIsPositive)
|
||||
{
|
||||
@ -798,7 +800,7 @@ void Pet::Update(uint32 diff)
|
||||
else
|
||||
{
|
||||
m_tempspell = 0;
|
||||
m_tempspellTarget = nullptr;
|
||||
m_tempspellTarget = ObjectGuid::Empty;
|
||||
m_tempoldTarget = ObjectGuid::Empty;
|
||||
m_tempspellIsPositive = false;
|
||||
|
||||
@ -2433,7 +2435,7 @@ void Pet::CastWhenWillAvailable(uint32 spellid, Unit* spellTarget, ObjectGuid ol
|
||||
if (!spellTarget)
|
||||
return;
|
||||
|
||||
m_tempspellTarget = spellTarget;
|
||||
m_tempspellTarget = spellTarget->GetGUID();
|
||||
m_tempspell = spellid;
|
||||
m_tempspellIsPositive = spellIsPositive;
|
||||
|
||||
@ -2445,7 +2447,7 @@ void Pet::ClearCastWhenWillAvailable()
|
||||
{
|
||||
m_tempspellIsPositive = false;
|
||||
m_tempspell = 0;
|
||||
m_tempspellTarget = nullptr;
|
||||
m_tempspellTarget = ObjectGuid::Empty;
|
||||
m_tempoldTarget = ObjectGuid::Empty;
|
||||
}
|
||||
|
||||
|
||||
@ -158,7 +158,7 @@ protected:
|
||||
|
||||
std::unique_ptr<DeclinedName> m_declinedname;
|
||||
|
||||
Unit* m_tempspellTarget;
|
||||
ObjectGuid m_tempspellTarget;
|
||||
ObjectGuid m_tempoldTarget;
|
||||
bool m_tempspellIsPositive;
|
||||
uint32 m_tempspell;
|
||||
|
||||
@ -441,7 +441,10 @@ void WorldSession::HandlePetActionHelper(Unit* pet, ObjectGuid guid1, uint32 spe
|
||||
bool haspositiveeffect = false;
|
||||
|
||||
if (!unit_target)
|
||||
{
|
||||
delete spell;
|
||||
return;
|
||||
}
|
||||
|
||||
// search positive effects for spell
|
||||
for (uint8 i = 0; i < MAX_SPELL_EFFECTS; ++i)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user