Skip to content

Fix memory leaks in GameEventMgr, MotionMaster, ObjectMgr and Pet#3220

Closed
schell244 wants to merge 1 commit intovmangos:developmentfrom
schell244:fix_memory_leaks
Closed

Fix memory leaks in GameEventMgr, MotionMaster, ObjectMgr and Pet#3220
schell244 wants to merge 1 commit intovmangos:developmentfrom
schell244:fix_memory_leaks

Conversation

@schell244
Copy link
Copy Markdown
Contributor

🍰 Pullrequest

Fix some memory leaks and uninitialized member variables discovered during Valgrind profiling.

  • GameEventMgr: Implement destructor to clean up mGameEventHardcodedList entries
  • MotionMaster: Fix memory leak in ClearType() by deleting non-static movement generators
  • ObjectMgr: Add cleanup methods for item prototypes and creature auras
  • Pet: Add ClearCharmInfo() call in destructor
  • MasterPlayer: Initialize unReadMails and m_nextMailDelivereTime in constructor
  • battleground_alterac: Initialize Event_Timer and Point in Reset()
  • MotionMaster: Remove stray semicolon
  • PlayerBotAI: Add cleanup on error path and PvP flag initialization

Proof

  • None

Issues

  • None

How2Test

  • None

Todo / Checklist

  • None

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR targets leaks and uninitialized state discovered during Valgrind profiling across core systems (events, movement, object/item templates, pets, bots, and some scripts).

Changes:

  • Add explicit cleanup paths for dynamically allocated objects (GameEventMgr hardcoded events, MotionMaster generators, ObjectMgr item prototype strings + creature aura arrays, Pet charm info).
  • Initialize previously uninitialized members/fields (MasterPlayer mail fields, AV escort AI state).
  • Improve error-path cleanup and initialization in bot player spawning (packet broadcaster cleanup, PvP flag initialization).

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/scripts/kalimdor/silithus/temple_of_ahnqiraj/boss_skeram.cpp Fixes reset-state initialization for boss image pointers.
src/scripts/battlegrounds/battleground_alterac.cpp Initializes AV escort AI state in Reset().
src/game/Spells/SpellAuras.cpp Adds notes around SpellModifier allocation in dummy aura handling.
src/game/PlayerBots/PlayerBotAI.cpp Adds PvP zone initialization and additional error-path cleanup when spawning bot players.
src/game/Objects/Pet.cpp Clears charm info in Pet destructor to avoid leaks.
src/game/Objects/Creature.cpp Adds a note about potential CreatureGroup lifetime/leak behavior.
src/game/ObjectMgr.h Declares new cleanup helpers for item prototypes and creature auras.
src/game/ObjectMgr.cpp Implements cleanup helpers and calls them on reload/destruction; adds per-entry aura cleanup in LoadCreatureInfo.
src/game/Movement/MotionMaster.cpp Removes stray semicolon; deletes non-static movement generators in ClearType().
src/game/GameEventMgr.h Makes GameEventMgr destructor non-inline to allow cleanup.
src/game/GameEventMgr.cpp Implements destructor to delete hardcoded event instances.
src/game/Chat/MasterPlayer.cpp Initializes mail-related members in constructor.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/game/Spells/SpellAuras.cpp Outdated
Comment on lines 2089 to 2091
// MEMORY LEAK: SpellModifier created with 'new' but not stored in m_spellmod.
// On remove, GetSpellMod() may fail to find it, causing a leak.
if (Player* pPlayer = target->ToPlayer())
Comment on lines +4153 to 4155
// MEMORY LEAK: CreatureGroup created with 'new' and members added via AddMember().
// If creature is destroyed without LeaveCreatureGroup(), member entries leak.
CreatureGroup* group = leader->GetCreatureGroup();
Comment thread src/game/Movement/MotionMaster.cpp Outdated
Comment on lines 909 to 914
MovementGenerator* mg = *it;
mg->Finalize(*m_owner);
erase(it);
if (!isStatic(mg))
delete mg;
it = begin();
{
sLog.Out(LOG_BASIC, LOG_LVL_ERROR, "PlayerBotAI::SpawnNewPlayer: Unable to add player to map!");
newChar->DeletePacketBroadcaster();
delete mPlayer;
Comment thread src/game/Spells/SpellAuras.cpp Outdated
Comment on lines 2068 to 2070
// MEMORY LEAK: SpellModifier created with 'new' but not stored in m_spellmod.
// On remove, GetSpellMod() may fail to find it, causing a leak.
if (Player* pPlayer = target->ToPlayer())
@ratkosrb
Copy link
Copy Markdown
Contributor

ratkosrb commented Apr 2, 2026

I've applied the fixes that are actually legit.

@ratkosrb ratkosrb closed this Apr 2, 2026
@schell244 schell244 deleted the fix_memory_leaks branch April 14, 2026 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants