[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
+4 -1
View File
@@ -1158,6 +1158,7 @@ void Mob::CreateSpawnPacket(EQApplicationPacket *app, Mob *ForWho)
{
app->SetOpcode(OP_NewSpawn);
app->size = sizeof(NewSpawn_Struct);
safe_delete_array(app->pBuffer);
app->pBuffer = new uchar[app->size];
memset(app->pBuffer, 0, app->size);
auto ns = (NewSpawn_Struct *) app->pBuffer;
@@ -1175,7 +1176,7 @@ void Mob::CreateSpawnPacket(EQApplicationPacket *app, Mob *ForWho)
void Mob::CreateSpawnPacket(EQApplicationPacket* app, NewSpawn_Struct* ns) {
app->SetOpcode(OP_NewSpawn);
app->size = sizeof(NewSpawn_Struct);
safe_delete_array(app->pBuffer);
app->pBuffer = new uchar[sizeof(NewSpawn_Struct)];
// Copy ns directly into packet
@@ -1367,6 +1368,7 @@ void Mob::CreateDespawnPacket(EQApplicationPacket* app, bool Decay)
{
app->SetOpcode(OP_DeleteSpawn);
app->size = sizeof(DeleteSpawn_Struct);
safe_delete_array(app->pBuffer);
app->pBuffer = new uchar[app->size];
memset(app->pBuffer, 0, app->size);
DeleteSpawn_Struct* ds = (DeleteSpawn_Struct*)app->pBuffer;
@@ -1380,6 +1382,7 @@ void Mob::CreateHPPacket(EQApplicationPacket* app)
IsFullHP=(current_hp>=max_hp);
app->SetOpcode(OP_MobHealth);
app->size = sizeof(SpawnHPUpdate_Struct2);
safe_delete_array(app->pBuffer);
app->pBuffer = new uchar[app->size];
memset(app->pBuffer, 0, sizeof(SpawnHPUpdate_Struct2));
SpawnHPUpdate_Struct2* ds = (SpawnHPUpdate_Struct2*)app->pBuffer;