Core/Pet: Fixed possible crash after swapping pet with stable master. Closes #5177

This commit is contained in:
kaelima
2012-02-21 16:50:45 +01:00
parent 2f37e82097
commit c15f7bfc19
+10 -4
View File
@@ -853,16 +853,22 @@ void WorldSession::HandleStableSwapPetCallback(PreparedQueryResult result, uint3
return;
}
// move alive pet to slot or delete dead pet
Pet* pet = _player->GetPet();
// The player's pet could have been removed during the delay of the DB callback
if (!pet)
{
SendStableResult(STABLE_ERR_STABLE);
return;
}
// move alive pet to slot or delete dead pet
_player->RemovePet(pet, pet->isAlive() ? PetSaveMode(slot) : PET_SAVE_AS_DELETED);
// summon unstabled pet
Pet* newpet = new Pet(_player);
if (!newpet->LoadPetFromDB(_player, petEntry, petId))
Pet* newPet = new Pet(_player);
if (!newPet->LoadPetFromDB(_player, petEntry, petId))
{
delete newpet;
delete newPet;
SendStableResult(STABLE_ERR_STABLE);
}
else