Fix for possible memory leak when spawning bots

This commit is contained in:
Uleat
2018-02-19 07:34:43 -05:00
parent c36a1cd6dc
commit 765ee5eeed
4 changed files with 39 additions and 15 deletions
+16 -8
View File
@@ -3053,7 +3053,7 @@ void Bot::Depop() {
NPC::Depop(false);
}
void Bot::Spawn(Client* botCharacterOwner) {
bool Bot::Spawn(Client* botCharacterOwner) {
if(GetBotID() > 0 && _botOwnerCharacterID > 0 && botCharacterOwner && botCharacterOwner->CharacterID() == _botOwnerCharacterID) {
// Rename the bot name to make sure that Mob::GetName() matches Mob::GetCleanName() so we dont have a bot named "Jesuschrist001"
strcpy(name, GetCleanName());
@@ -3097,7 +3097,11 @@ void Bot::Spawn(Client* botCharacterOwner) {
this->SendWearChange(materialFromSlot);
}
}
return true;
}
return false;
}
// Deletes the inventory record for the specified item from the database for this bot.
@@ -3246,16 +3250,20 @@ void Bot::LoadAndSpawnAllZonedBots(Client* botOwner) {
if(!ActiveBots.empty()) {
for(std::list<uint32>::iterator itr = ActiveBots.begin(); itr != ActiveBots.end(); ++itr) {
Bot* activeBot = Bot::LoadBot(*itr);
if (!activeBot)
continue;
if(activeBot) {
activeBot->Spawn(botOwner);
g->UpdatePlayer(activeBot);
// follow the bot owner, not the group leader we just zoned with our owner.
if(g->IsGroupMember(botOwner) && g->IsGroupMember(activeBot))
activeBot->SetFollowID(botOwner->GetID());
if (!activeBot->Spawn(botOwner)) {
safe_delete(activeBot);
continue;
}
if(activeBot && !botOwner->HasGroup())
g->UpdatePlayer(activeBot);
// follow the bot owner, not the group leader we just zoned with our owner.
if (g->IsGroupMember(botOwner) && g->IsGroupMember(activeBot))
activeBot->SetFollowID(botOwner->GetID());
if(!botOwner->HasGroup())
database.SetGroupID(activeBot->GetCleanName(), 0, activeBot->GetBotID());
}
}