Fix potential memory leaks (clang-tidy)

This commit is contained in:
Michael Cook (mackal) 2016-05-06 22:58:45 -04:00
parent 74b3fe9d61
commit 47c9182ba3
7 changed files with 183 additions and 158 deletions

View File

@ -2568,15 +2568,14 @@ void Client::LogMerchant(Client* player, Mob* merchant, uint32 quantity, uint32
}
}
bool Client::BindWound(Mob* bindmob, bool start, bool fail){
EQApplicationPacket* outapp = 0;
if(!fail)
bool Client::BindWound(Mob *bindmob, bool start, bool fail)
{
EQApplicationPacket *outapp = nullptr;
if (!fail) {
outapp = new EQApplicationPacket(OP_Bind_Wound, sizeof(BindWound_Struct));
BindWound_Struct *bind_out = (BindWound_Struct *)outapp->pBuffer;
// Start bind
if(!bindwound_timer.Enabled())
{
if (!bindwound_timer.Enabled()) {
// make sure we actually have a bandage... and consume it.
int16 bslot = m_inv.HasItemByUse(ItemTypeBandage, 1, invWhereWorn | invWherePersonal);
if (bslot == INVALID_INDEX) {
@ -2584,6 +2583,7 @@ bool Client::BindWound(Mob* bindmob, bool start, bool fail){
QueuePacket(outapp);
bind_out->type = 7; // this is the wrong message, dont know the right one.
QueuePacket(outapp);
safe_delete(outapp);
return (true);
}
DeleteItemInInventory(bslot, 1, true); // do we need client update?
@ -2604,21 +2604,18 @@ bool Client::BindWound(Mob* bindmob, bool start, bool fail){
bind_out->type = 0;
bindwound_timer.Disable();
bindwound_target = 0;
}
else {
} else {
// send bindmob "stand still"
if (!bindmob->IsAIControlled() && bindmob != this) {
bindmob->CastToClient()->Message_StringID(clientMessageYellow, YOU_ARE_BEING_BANDAGED);
}
else if (bindmob->IsAIControlled() && bindmob != this ){
bindmob->CastToClient()->Message_StringID(clientMessageYellow,
YOU_ARE_BEING_BANDAGED);
} else if (bindmob->IsAIControlled() && bindmob != this) {
; // Tell IPC to stand still?
}
else {
} else {
; // Binding self
}
}
}
else if (bindwound_timer.Check()) // Did the timer finish?
} else if (bindwound_timer.Check()) // Did the timer finish?
{
// finish bind
// disable complete timer
@ -2636,11 +2633,9 @@ bool Client::BindWound(Mob* bindmob, bool start, bool fail){
// send bindmob bind done
if (!bindmob->IsAIControlled() && bindmob != this) {
}
else if(bindmob->IsAIControlled() && bindmob != this ) {
} else if (bindmob->IsAIControlled() && bindmob != this) {
// Tell IPC to resume??
}
else {
} else {
// Binding self
}
// Send client bind done
@ -2650,7 +2645,8 @@ bool Client::BindWound(Mob* bindmob, bool start, bool fail){
bind_out->type = 0;
CheckIncreaseSkill(SkillBindWound, nullptr, 5);
int maxHPBonus = spellbonuses.MaxBindWound + itembonuses.MaxBindWound + aabonuses.MaxBindWound;
int maxHPBonus = spellbonuses.MaxBindWound + itembonuses.MaxBindWound +
aabonuses.MaxBindWound;
int max_percent = 50 + 10 * maxHPBonus;
@ -2667,7 +2663,6 @@ bool Client::BindWound(Mob* bindmob, bool start, bool fail){
// 0.120 per skill point, 0.60 per skill level, minimum 3 max 30
int bindhps = 3;
if (GetSkill(SkillBindWound) > 200) {
bindhps += GetSkill(SkillBindWound) * 4 / 10;
} else if (GetSkill(SkillBindWound) >= 10) {
@ -2675,7 +2670,8 @@ bool Client::BindWound(Mob* bindmob, bool start, bool fail){
}
// Implementation of aaMithanielsBinding is a guess (the multiplier)
int bindBonus = spellbonuses.BindWound + itembonuses.BindWound + aabonuses.BindWound;
int bindBonus = spellbonuses.BindWound + itembonuses.BindWound +
aabonuses.BindWound;
bindhps += bindhps * bindBonus / 100;
@ -2690,16 +2686,18 @@ bool Client::BindWound(Mob* bindmob, bool start, bool fail){
bindmob->SetHP(chp);
bindmob->SendHPUpdate();
}
else {
} else {
// I dont have the real, live
Message(15, "You cannot bind wounds above %d%% hitpoints.", max_percent);
Message(15, "You cannot bind wounds above %d%% hitpoints.",
max_percent);
if (bindmob != this && bindmob->IsClient())
bindmob->CastToClient()->Message(15, "You cannot have your wounds bound above %d%% hitpoints.", max_percent);
bindmob->CastToClient()->Message(
15,
"You cannot have your wounds bound above %d%% hitpoints.",
max_percent);
// Too many hp message goes here.
}
}
else {
} else {
// Send client bind failed
if (bindmob != this)
bind_out->type = 6; // They moved
@ -2711,8 +2709,7 @@ bool Client::BindWound(Mob* bindmob, bool start, bool fail){
}
}
}
}
else if (bindwound_timer.Enabled()) {
} else if (bindwound_timer.Enabled()) {
// You moved
outapp = new EQApplicationPacket(OP_Bind_Wound, sizeof(BindWound_Struct));
BindWound_Struct *bind_out = (BindWound_Struct *)outapp->pBuffer;
@ -3649,19 +3646,25 @@ void Client::SetEndurance(int32 newEnd)
SendManaUpdatePacket();
}
void Client::SacrificeConfirm(Client *caster) {
void Client::SacrificeConfirm(Client *caster)
{
EQApplicationPacket *outapp = new EQApplicationPacket(OP_Sacrifice, sizeof(Sacrifice_Struct));
Sacrifice_Struct *ss = (Sacrifice_Struct *)outapp->pBuffer;
if(!caster || PendingSacrifice) return;
if (!caster || PendingSacrifice) {
safe_delete(outapp);
return;
}
if (GetLevel() < RuleI(Spells, SacrificeMinLevel)) {
caster->Message_StringID(13, SAC_TOO_LOW); // This being is not a worthy sacrifice.
safe_delete(outapp);
return;
}
if (GetLevel() > RuleI(Spells, SacrificeMaxLevel)) {
caster->Message_StringID(13, SAC_TOO_HIGH);
safe_delete(outapp);
return;
}
@ -3803,13 +3806,16 @@ void Client::SetHoTT(uint32 mobid) {
safe_delete(outapp);
}
void Client::SendPopupToClient(const char *Title, const char *Text, uint32 PopupID, uint32 Buttons, uint32 Duration) {
void Client::SendPopupToClient(const char *Title, const char *Text, uint32 PopupID, uint32 Buttons, uint32 Duration)
{
EQApplicationPacket *outapp = new EQApplicationPacket(OP_OnLevelMessage, sizeof(OnLevelMessage_Struct));
OnLevelMessage_Struct *olms = (OnLevelMessage_Struct *)outapp->pBuffer;
if((strlen(Title) > (sizeof(olms->Title)-1)) ||
(strlen(Text) > (sizeof(olms->Text)-1))) return;
if ((strlen(Title) > (sizeof(olms->Title) - 1)) || (strlen(Text) > (sizeof(olms->Text) - 1))) {
safe_delete(outapp);
return;
}
strcpy(olms->Title, Title);
strcpy(olms->Text, Text);
@ -3843,8 +3849,10 @@ void Client::SendWindow(uint32 PopupID, uint32 NegativeID, uint32 Buttons, const
EQApplicationPacket* app = new EQApplicationPacket(OP_OnLevelMessage, sizeof(OnLevelMessage_Struct));
OnLevelMessage_Struct* olms=(OnLevelMessage_Struct*)app->pBuffer;
if(strlen(Text) > (sizeof(olms->Text)-1))
if(strlen(Text) > (sizeof(olms->Text)-1)) {
safe_delete(app);
return;
}
if(!target)
title_type = 0;

View File

@ -13691,6 +13691,7 @@ void Client::Handle_OP_TraderShop(const EQApplicationPacket *app)
else {
Log.Out(Logs::Detail, Logs::Trading, "Client::Handle_OP_TraderShop: entity_list.GetClientByID(tcs->traderid)"
" returned a nullptr pointer");
safe_delete(outapp);
return;
}

View File

@ -3171,6 +3171,7 @@ void command_equipitem(Client *c, const Seperator *sep)
if (partialmove) { // remove this con check if someone can figure out removing charges from cursor stack issue below
// mi->number_in_stack is always from_inst->GetCharges() when partialmove is false
c->Message(13, "Error: Partial stack added to existing stack exceeds allowable stacksize");
safe_delete(outapp);
return;
}
else if(c->SwapItem(mi)) {

View File

@ -4567,6 +4567,7 @@ void EntityList::ExpeditionWarning(uint32 minutes_left)
it->second->QueuePacket(outapp);
++it;
}
safe_delete(outapp);
}
Mob *EntityList::GetClosestMobByBodyType(Mob *sender, bodyType BodyType)

View File

@ -383,6 +383,7 @@ void Mob::MakePoweredPet(uint16 spell_id, const char* pettype, int16 petpower,
"ORDER BY RAND() LIMIT 1", zone->GetShortName());
auto results = database.QueryDatabase(query);
if (!results.Success()) {
safe_delete(npc_type);
return;
}

View File

@ -139,14 +139,15 @@ bool SpawnGroupList::RemoveSpawnGroup(uint32 in_id) {
return(true);
}
bool ZoneDatabase::LoadSpawnGroups(const char* zone_name, uint16 version, SpawnGroupList* spawn_group_list) {
bool ZoneDatabase::LoadSpawnGroups(const char *zone_name, uint16 version, SpawnGroupList *spawn_group_list)
{
std::string query = StringFormat("SELECT DISTINCT(spawngroupID), spawngroup.name, spawngroup.spawn_limit, "
"spawngroup.dist, spawngroup.max_x, spawngroup.min_x, "
"spawngroup.max_y, spawngroup.min_y, spawngroup.delay, "
"spawngroup.despawn, spawngroup.despawn_timer, spawngroup.mindelay "
"FROM spawn2, spawngroup WHERE spawn2.spawngroupID = spawngroup.ID "
"AND spawn2.version = %u and zone = '%s'", version, zone_name);
"AND spawn2.version = %u and zone = '%s'",
version, zone_name);
auto results = QueryDatabase(query);
if (!results.Success()) {
return false;
@ -164,7 +165,8 @@ bool ZoneDatabase::LoadSpawnGroups(const char* zone_name, uint16 version, SpawnG
"FROM spawnentry, spawn2, npc_types "
"WHERE spawnentry.npcID=npc_types.id "
"AND spawnentry.spawngroupID = spawn2.spawngroupID "
"AND zone = '%s'", zone_name);
"AND zone = '%s'",
zone_name);
results = QueryDatabase(query);
if (!results.Success()) {
Log.Out(Logs::General, Logs::Error, "Error2 in PopulateZoneLists query '%'", query.c_str());
@ -176,6 +178,7 @@ bool ZoneDatabase::LoadSpawnGroups(const char* zone_name, uint16 version, SpawnG
SpawnGroup *sg = spawn_group_list->GetSpawnGroup(atoi(row[0]));
if (!sg) {
safe_delete(newSpawnEntry);
continue;
}
@ -185,14 +188,14 @@ bool ZoneDatabase::LoadSpawnGroups(const char* zone_name, uint16 version, SpawnG
return true;
}
bool ZoneDatabase::LoadSpawnGroupsByID(int spawngroupid, SpawnGroupList* spawn_group_list) {
bool ZoneDatabase::LoadSpawnGroupsByID(int spawngroupid, SpawnGroupList *spawn_group_list)
{
std::string query = StringFormat("SELECT DISTINCT(spawngroup.id), spawngroup.name, spawngroup.spawn_limit, "
"spawngroup.dist, spawngroup.max_x, spawngroup.min_x, "
"spawngroup.max_y, spawngroup.min_y, spawngroup.delay, "
"spawngroup.despawn, spawngroup.despawn_timer, spawngroup.mindelay "
"FROM spawngroup WHERE spawngroup.ID = '%i'", spawngroupid);
"FROM spawngroup WHERE spawngroup.ID = '%i'",
spawngroupid);
auto results = QueryDatabase(query);
if (!results.Success()) {
Log.Out(Logs::General, Logs::Error, "Error2 in PopulateZoneLists query %s", query.c_str());
@ -200,14 +203,17 @@ bool ZoneDatabase::LoadSpawnGroupsByID(int spawngroupid, SpawnGroupList* spawn_g
}
for (auto row = results.begin(); row != results.end(); ++row) {
SpawnGroup* newSpawnGroup = new SpawnGroup(atoi(row[0]), row[1], atoi(row[2]), atof(row[3]), atof(row[4]), atof(row[5]), atof(row[6]), atof(row[7]), atoi(row[8]), atoi(row[9]), atoi(row[10]), atoi(row[11]));
SpawnGroup *newSpawnGroup = new SpawnGroup(atoi(row[0]), row[1], atoi(row[2]), atof(row[3]),
atof(row[4]), atof(row[5]), atof(row[6]), atof(row[7]),
atoi(row[8]), atoi(row[9]), atoi(row[10]), atoi(row[11]));
spawn_group_list->AddSpawnGroup(newSpawnGroup);
}
query = StringFormat("SELECT DISTINCT(spawnentry.spawngroupID), spawnentry.npcid, "
"spawnentry.chance, spawngroup.spawn_limit FROM spawnentry, spawngroup "
"WHERE spawnentry.spawngroupID = '%i' AND spawngroup.spawn_limit = '0' "
"ORDER BY chance", spawngroupid);
"ORDER BY chance",
spawngroupid);
results = QueryDatabase(query);
if (!results.Success()) {
Log.Out(Logs::General, Logs::Error, "Error3 in PopulateZoneLists query '%s'", query.c_str());
@ -218,6 +224,7 @@ bool ZoneDatabase::LoadSpawnGroupsByID(int spawngroupid, SpawnGroupList* spawn_g
SpawnEntry *newSpawnEntry = new SpawnEntry(atoi(row[1]), atoi(row[2]), row[3] ? atoi(row[3]) : 0);
SpawnGroup *sg = spawn_group_list->GetSpawnGroup(atoi(row[0]));
if (!sg) {
safe_delete(newSpawnEntry);
continue;
}

View File

@ -2401,8 +2401,10 @@ void Client::SendBuyerResults(char* searchString, uint32 searchID) {
const Item_Struct* item = database.GetItem(itemID);
if(!item)
if(!item) {
safe_delete(outapp);
continue;
}
// Save having to scan the client list when dealing with multiple buylines for the same Character.
if(charID != lastCharID) {
@ -2410,8 +2412,10 @@ void Client::SendBuyerResults(char* searchString, uint32 searchID) {
lastCharID = charID;
}
if(!buyer)
if(!buyer) {
safe_delete(outapp);
continue;
}
VARSTRUCT_ENCODE_TYPE(uint32, buf, Barter_BuyerSearchResults); // Command
VARSTRUCT_ENCODE_TYPE(uint32, buf, searchID); // Match up results with the request
@ -2493,8 +2497,10 @@ void Client::ShowBuyLines(const EQApplicationPacket *app) {
const Item_Struct* item = database.GetItem(ItemID);
if(!item)
if(!item) {
safe_delete(outapp);
continue;
}
VARSTRUCT_ENCODE_TYPE(uint32, Buf, Barter_BuyerInspectWindow);
VARSTRUCT_ENCODE_TYPE(uint32, Buf, BuySlot);