[Bug Fix] Fix miscellaneous memory leaks related to EQApplicationPacket and it's pBuffer (#2262)

* Delete EQApplicationPacket after use

* Correct issue where Creating EQApplicationPackets in zone/mob.cpp may not free pBuffer[]

* Handle freeing pBuffer[] if exists in zone/mob.cpp Create*Packet functions

* Handle freeing pBuffer[] in zone/object.cpp Create*Packet methods

* Delete leaked outapp variables in zone/trading.cpp

* Make CreateHorseSpawnPacket() safer by freeing pBuffer[] before replacing with new[]

* Prevent initial new ServerPacket from being leaked in command_reload

* Free pack after sending in command_setlsinfo

* Delete new NPC in command_viewnpctype after printing stats

* Fix compile error

* Delete EQApplicationPacket after sending in command_kick

* Remove unneeded safe_delete(outapp) after FastQueuePacket and fix minor whitespace issue

* Delete packet after sending in WorldServer::SendReloadTasks

* Cleanup logic and free leaked NPCType in Client::Doppelganger

* Free RespawnOption in Client::HandleRespawnFromHover in 'unexpected rez from hover request' branch

* Free EQApplicationPacket after sending in Bot::ProcessBotInspectionRequest

* Free Bot when returning from failed Bot::Save() in helper_bot_create()

* Initialize variable to nullptr to prevent garbage initial value

* Undo change in other PR
This commit is contained in:
Quintinon
2022-07-02 20:10:51 -07:00
committed by GitHub
parent 5c60913583
commit b5c4357de2
15 changed files with 46 additions and 39 deletions
+6 -10
View File
@@ -6517,8 +6517,6 @@ void Client::Doppelganger(uint16 spell_id, Mob *target, const char *name_overrid
}
made_npc->loottable_id = 0;
npc_type = made_npc;
int summon_count = pet.count;
if(summon_count > MAX_SWARM_PETS)
@@ -6531,14 +6529,11 @@ void Client::Doppelganger(uint16 spell_id, Mob *target, const char *name_overrid
};
while(summon_count > 0) {
NPCType *npc_dup = nullptr;
if(made_npc != nullptr) {
npc_dup = new NPCType;
memcpy(npc_dup, made_npc, sizeof(NPCType));
}
auto npc_type_copy = new NPCType;
memcpy(npc_type_copy, made_npc, sizeof(NPCType));
NPC* swarm_pet_npc = new NPC(
(npc_dup!=nullptr)?npc_dup:npc_type, //make sure we give the NPC the correct data pointer
npc_type_copy,
0,
GetPosition() + glm::vec4(swarmPetLocations[summon_count - 1], 0.0f, 0.0f),
GravityBehavior::Water);
@@ -6563,12 +6558,13 @@ void Client::Doppelganger(uint16 spell_id, Mob *target, const char *name_overrid
swarm_pet_npc->GetSwarmInfo()->target = 0;
//we allocated a new NPC type object, give the NPC ownership of that memory
if(npc_dup != nullptr)
swarm_pet_npc->GiveNPCTypeData(npc_dup);
swarm_pet_npc->GiveNPCTypeData(npc_type_copy);
entity_list.AddNPC(swarm_pet_npc);
summon_count--;
}
safe_delete(made_npc);
}
void Client::AssignToInstance(uint16 instance_id)