Fix mem leaks

This commit is contained in:
luis
2026-11-14 20:10:57 -03:00
parent 35bc846508
commit 8b24fce631
10 changed files with 100 additions and 17 deletions
@@ -3844,6 +3844,7 @@ void Player::DeleteFromDB(ObjectGuid playerguid, uint32 accountId, bool updateRe
// The house dies with the character on every removal path (final purge after the undelete
// window, account unlink); the delete request already handled it, this is idempotent.
sHousingMgr.DeleteHouseForOwner(playerguid);
sHousingMgr.RemoveIgnoredNeighborhoods(playerguid);
//WowCommunity
uint32 charDeleteMethod = sWorld->getIntConfig(CONFIG_CHARDELETE_METHOD);
CharacterCacheEntry const* characterInfo = sCharacterCache->GetCharacterCacheByGuid(playerguid);
+5
View File
@@ -1716,6 +1716,11 @@ void HousingMgr::AddIgnoredNeighborhood(ObjectGuid playerGuid, ObjectGuid neighb
CharacterDatabase.Execute(stmt);
}
void HousingMgr::RemoveIgnoredNeighborhoods(ObjectGuid playerGuid)
{
_ignoredNeighborhoods.erase(playerGuid);
}
void HousingMgr::RemoveIgnoredNeighborhood(ObjectGuid playerGuid, ObjectGuid neighborhoodGuid)
{
std::unordered_set<ObjectGuid>& set = EnsureIgnoredNeighborhoodsLoaded(playerGuid);
+2
View File
@@ -380,6 +380,8 @@ public:
bool IsNeighborhoodIgnored(ObjectGuid playerGuid, ObjectGuid neighborhoodGuid);
void AddIgnoredNeighborhood(ObjectGuid playerGuid, ObjectGuid neighborhoodGuid);
void RemoveIgnoredNeighborhood(ObjectGuid playerGuid, ObjectGuid neighborhoodGuid);
// Drops the cached list of a player that is leaving the world (reloaded from DB on next use).
void RemoveIgnoredNeighborhoods(ObjectGuid playerGuid);
private:
std::mutex _pendingPlotTeleportsLock;
+3
View File
@@ -37,6 +37,7 @@
#include "Group.h"
#include "Guild.h"
#include "GuildMgr.h"
#include "HousingMgr.h"
#include "Hyperlinks.h"
#include "IpAddress.h"
#include "Log.h"
@@ -579,6 +580,8 @@ void WorldSession::LogoutPlayer(bool save)
sLFGListMgr.RemoveListingsBy(_player->GetGUID());
sLFGListMgr.RemoveApplicationsBy(_player->GetGUID());
sLFGListMgr.UnregisterSearch(_player->GetGUID());
// The house finder ignore list is DB backed, drop the cached copy with the session.
sHousingMgr.RemoveIgnoredNeighborhoods(_player->GetGUID());
//WowCommunity
if (!_player->GetLootGUID().IsEmpty())
DoLootReleaseAll();
@@ -26,6 +26,7 @@ FSB_BaseAI::~FSB_BaseAI()
{
FSBChatMgr::Get()->LeaveBotChannels(me);
FSBChatMgr::Get()->UnregisterActiveBot(me);
GenAINpcMemoryMgr::Get()->Erase(me->GetGUID());
delete botDungeonData;
delete botBattlegroundData;
}
@@ -72,6 +72,13 @@ void GenAINpcMemoryMgr::ClearMemory(ObjectGuid npcGuid)
it->second.clear();
}
void GenAINpcMemoryMgr::Erase(ObjectGuid npcGuid)
{
std::unique_lock<std::shared_mutex> lock(_mutex);
_memories.erase(npcGuid);
_questStates.erase(npcGuid);
}
void GenAINpcMemoryMgr::RemoveIfUnused(ObjectGuid npcGuid)
{
std::unique_lock<std::shared_mutex> lock(_mutex);
@@ -39,6 +39,7 @@ public:
void AddEntry(ObjectGuid npcGuid, uint32 channelId, std::string const& sender, std::string const& msg, bool isPlayer);
std::deque<BotChatMemoryEntry> GetMemory(ObjectGuid npcGuid) const;
void ClearMemory(ObjectGuid npcGuid);
void Erase(ObjectGuid npcGuid);
void RemoveIfUnused(ObjectGuid npcGuid);
uint8 GetQuestState(ObjectGuid npcGuid) const;
@@ -94,8 +94,15 @@ void FSBChatMgr::UnregisterActiveBot(Creature* bot)
{
if (!bot)
return;
std::lock_guard<std::mutex> lock(_activeBotsMutex);
_activeBots.erase(bot->GetGUID());
{
std::lock_guard<std::mutex> lock(_activeBotsMutex);
_activeBots.erase(bot->GetGUID());
}
// The bot is gone, its reply cooldown has no owner left to throttle.
std::lock_guard<std::mutex> cooldownLock(_botReplyCooldownsMutex);
_botReplyCooldowns.erase(bot->GetGUID());
}
std::vector<Creature*> FSBChatMgr::GetActiveBots()
@@ -319,8 +326,14 @@ void FSBChatMgr::HandlePlayerGeneralChat(Player* player, Channel* channel, std::
if (FSBMgr::Get()->IsBotOwned(bot))
continue;
auto cdIt = _botReplyCooldowns.find(bot->GetGUID());
if (cdIt != _botReplyCooldowns.end() && now < cdIt->second + cooldownMs)
bool onCooldown = false;
{
std::lock_guard<std::mutex> lock(_botReplyCooldownsMutex);
auto cdIt = _botReplyCooldowns.find(bot->GetGUID());
onCooldown = cdIt != _botReplyCooldowns.end() && now < cdIt->second + cooldownMs;
}
if (onCooldown)
continue;
if (urand(0, 99) >= chance)
@@ -405,7 +418,10 @@ void FSBChatMgr::HandlePlayerGeneralChat(Player* player, Channel* channel, std::
_pendingReplies.push_back(state);
}
_botReplyCooldowns[bot->GetGUID()] = now;
{
std::lock_guard<std::mutex> lock(_botReplyCooldownsMutex);
_botReplyCooldowns[bot->GetGUID()] = now;
}
}
}
@@ -125,6 +125,7 @@ private:
std::unordered_map<ObjectGuid, Creature*> _activeBots;
mutable std::mutex _activeBotsMutex;
std::unordered_map<ObjectGuid, uint32> _botReplyCooldowns;
std::mutex _botReplyCooldownsMutex;
std::vector<std::shared_ptr<PendingBotReply>> _pendingReplies;
std::mutex _pendingRepliesMutex;
+58 -12
View File
@@ -36,7 +36,10 @@
#include "TaskScheduler.h"
#include "TemporarySummon.h"
#include <algorithm>
#include <chrono>
#include <mutex>
#include <unordered_map>
#include <vector>
enum MageSpells
{
@@ -1224,12 +1227,50 @@ private:
};
// Track Brain Freeze boosted Flurry casts by OriginalCastId (workaround for aura interrupt issues)
// Key = Flurry(44614) CastId, Value = pending missiles for that Flurry cast
static std::unordered_map<ObjectGuid, int32> g_BrainFreezePendingMissiles;
// Key = Flurry(44614) CastId, Value = pending missiles and the time the cast stops being relevant
struct BrainFreezeCastState
{
int32 pendingMissiles;
std::chrono::steady_clock::time_point expires;
};
static std::mutex g_BrainFreezeStateMutex;
static std::unordered_map<ObjectGuid, BrainFreezeCastState> g_BrainFreezePendingMissiles;
// Translation map: 228596's CastId -> Flurry's CastId (so 228354 can find its counter)
static std::unordered_map<ObjectGuid, ObjectGuid> g_BrainFreezeCastIdChain;
// All missiles of a Flurry land within ~1.5s. Anything older belongs to a cast that never
// finished (interrupted, target lost, caster died) and must not stay cached forever.
static constexpr std::chrono::seconds BrainFreezeStateLifetime(30);
// Must be called with g_BrainFreezeStateMutex held.
static void EraseBrainFreezeCast(ObjectGuid flurryCastId)
{
g_BrainFreezePendingMissiles.erase(flurryCastId);
// Every missile of the cast registers its own chain entry, all of them point at the same Flurry.
for (auto chainItr = g_BrainFreezeCastIdChain.begin(); chainItr != g_BrainFreezeCastIdChain.end();)
{
if (chainItr->second == flurryCastId)
chainItr = g_BrainFreezeCastIdChain.erase(chainItr);
else
++chainItr;
}
}
// Must be called with g_BrainFreezeStateMutex held.
static void PruneBrainFreezeState(std::chrono::steady_clock::time_point now)
{
std::vector<ObjectGuid> expired;
for (auto const& [castId, state] : g_BrainFreezePendingMissiles)
if (now >= state.expires)
expired.push_back(castId);
for (ObjectGuid castId : expired)
EraseBrainFreezeCast(castId);
}
// 44614 - Flurry (cast) - Manual missile control
class spell_mage_flurry : public SpellScript
{
@@ -1252,12 +1293,18 @@ class spell_mage_flurry : public SpellScript
ObjectGuid castId = GetSpell()->m_castId;
if (Aura* brainFreeze = caster->GetAura(SPELL_MAGE_BRAIN_FREEZE_BUFF))
{
g_BrainFreezePendingMissiles[castId] = numMissiles;
{
std::lock_guard lock(g_BrainFreezeStateMutex);
std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now();
PruneBrainFreezeState(now);
g_BrainFreezePendingMissiles[castId] = { numMissiles, now + BrainFreezeStateLifetime };
}
caster->RemoveAura(brainFreeze); // Remove immediately so it doesn't get interrupted
}
else
{
g_BrainFreezePendingMissiles.erase(castId);
std::lock_guard lock(g_BrainFreezeStateMutex);
EraseBrainFreezeCast(castId);
}
// Cast first missile immediately
@@ -1301,7 +1348,8 @@ class spell_mage_flurry_damage_spell : public SpellScript
// Check if our originalCastId (Flurry's CastId) has a Brain Freeze entry
ObjectGuid flurryCastId = GetSpell()->m_originalCastId;
ObjectGuid myCastId = GetSpell()->m_castId;
std::lock_guard lock(g_BrainFreezeStateMutex);
auto it = g_BrainFreezePendingMissiles.find(flurryCastId);
if (it != g_BrainFreezePendingMissiles.end())
g_BrainFreezeCastIdChain[myCastId] = flurryCastId;
@@ -1352,6 +1400,7 @@ class spell_mage_flurry_missile_damage : public SpellScript
// Brain Freeze: +50% damage per missile if this cast had the buff
ObjectGuid damageSpellCastId = GetSpell()->m_originalCastId;
std::lock_guard lock(g_BrainFreezeStateMutex);
auto chainIt = g_BrainFreezeCastIdChain.find(damageSpellCastId);
if (chainIt == g_BrainFreezeCastIdChain.end())
return;
@@ -1359,18 +1408,15 @@ class spell_mage_flurry_missile_damage : public SpellScript
ObjectGuid flurryCastId = chainIt->second;
auto it = g_BrainFreezePendingMissiles.find(flurryCastId);
if (it == g_BrainFreezePendingMissiles.end() || it->second <= 0)
if (it == g_BrainFreezePendingMissiles.end() || it->second.pendingMissiles <= 0)
return;
int32 currentDamage = GetHitDamage();
SetHitDamage(currentDamage + currentDamage / 2); // +50%
it->second--; // Consume one missile
if (it->second <= 0)
{
g_BrainFreezePendingMissiles.erase(it);
g_BrainFreezeCastIdChain.erase(chainIt);
}
it->second.pendingMissiles--; // Consume one missile
if (it->second.pendingMissiles <= 0)
EraseBrainFreezeCast(flurryCastId);
}
void Register() override