Skip to content

fix(recorder): Fix memory leak of RecorderClass::m_crcInfo#2713

Merged
xezon merged 9 commits into
TheSuperHackers:mainfrom
Caball009:fix_memory_leak_crcInfo
May 20, 2026
Merged

fix(recorder): Fix memory leak of RecorderClass::m_crcInfo#2713
xezon merged 9 commits into
TheSuperHackers:mainfrom
Caball009:fix_memory_leak_crcInfo

Conversation

@Caball009
Copy link
Copy Markdown

@Caball009 Caball009 commented May 14, 2026

This PR fixes a memory leak for RecorderClass::m_crcInfo. I decided to fix this one by not allocating the CRCInfo object dynamically. This did require a larger change of moving the class to the header, though.

See commits for clean diffs.

TODO:

  • Replicate in Generals.

@Caball009 Caball009 added Minor Severity: Minor < Major < Critical < Blocker Gen Relates to Generals ZH Relates to Zero Hour Memory Is memory related Fix Is fixing something, but is not user facing labels May 14, 2026
@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 14, 2026

Greptile Summary

This PR fixes a memory leak by converting RecorderClass::m_crcInfo from a heap-allocated pointer (CRCInfo*) — which was never deleted — to a value-type member (CRCInfo). To support value semantics, CRCInfo gains a default constructor and is moved from a file-static class in Recorder.cpp to a nested protected class in Recorder.h. The change is replicated identically in both Generals/ and GeneralsMD/.

  • CRCInfo is now a nested protected class inside RecorderClass in the header; its implementations in the .cpp files are updated with the RecorderClass::CRCInfo:: qualifier.
  • All m_crcInfo->method() call sites become m_crcInfo.method(), and the NEW CRCInfo(...) allocation in playbackFile() is replaced with a plain value-copy assignment, correctly re-initialising state for successive replays.

Confidence Score: 5/5

Safe to merge — the change is a straightforward pointer-to-value refactor with no new logic introduced and no remaining raw allocations.

All four files are mechanical transformations of the same fix: the nested class is well-formed, the default constructor correctly initialises all fields, successive calls to playbackFile() properly reset state via value assignment, and the empty destructor no longer needs to manage any heap allocation. Both game directories are updated in lockstep.

No files require special attention.

Important Files Changed

Filename Overview
Generals/Code/GameEngine/Include/Common/Recorder.h CRCInfo nested class added to protected section; m_crcInfo changed from pointer to value member; includes are intact for the existing build system
Generals/Code/GameEngine/Source/Common/Recorder.cpp CRCInfo implementation moved to qualified RecorderClass::CRCInfo:: methods; default constructor added; all pointer dereferences converted to value access; NEW allocation replaced with value assignment
GeneralsMD/Code/GameEngine/Include/Common/Recorder.h Identical refactor to the Generals header; clean and consistent with its counterpart
GeneralsMD/Code/GameEngine/Source/Common/Recorder.cpp Identical refactor to the Generals .cpp; all call sites updated, no remaining raw pointer usage

Sequence Diagram

sequenceDiagram
    participant RC as RecorderClass
    participant CI as CRCInfo (value member)

    Note over RC,CI: Before this PR: CRCInfo* (heap-allocated, never deleted)
    Note over RC,CI: After this PR: CRCInfo (value member, auto-managed lifetime)

    RC->>CI: RecorderClass() — default CRCInfo() constructed in-place
    RC->>CI: "playbackFile() — m_crcInfo = CRCInfo(playerIndex, isMultiplayer)"
    loop Replay frames
        RC->>CI: "handleCRCMessage(fromPlayback=true) → addCRC(val)"
        RC->>CI: "handleCRCMessage(fromPlayback=false) → readCRC() / sawCRCMismatch()"
    end
    RC->>CI: ~RecorderClass() — CRCInfo destructor called automatically
Loading

Reviews (7): Last reviewed commit: "Moved 'm_crcInfo'." | Re-trigger Greptile

@Caball009 Caball009 force-pushed the fix_memory_leak_crcInfo branch from 282478b to c5e3079 Compare May 14, 2026 19:54
Comment thread GeneralsMD/Code/GameEngine/Include/Common/Recorder.h Outdated
Comment thread GeneralsMD/Code/GameEngine/Include/Common/Recorder.h Outdated
Comment thread GeneralsMD/Code/GameEngine/Include/Common/Recorder.h Outdated
Comment thread GeneralsMD/Code/GameEngine/Source/Common/Recorder.cpp
Comment thread GeneralsMD/Code/GameEngine/Include/Common/Recorder.h Outdated
Copy link
Copy Markdown

@xezon xezon left a comment

Choose a reason for hiding this comment

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

Looking good. Needs replicate to Generals.

Comment thread GeneralsMD/Code/GameEngine/Include/Common/Recorder.h Outdated
Comment thread GeneralsMD/Code/GameEngine/Include/Common/Recorder.h Outdated
Comment thread GeneralsMD/Code/GameEngine/Source/Common/Recorder.cpp
Comment thread GeneralsMD/Code/GameEngine/Include/Common/Recorder.h Outdated
@Caball009 Caball009 force-pushed the fix_memory_leak_crcInfo branch from e99381e to 82efc2a Compare May 19, 2026 22:14
@Caball009
Copy link
Copy Markdown
Author

Rebased to include the fix for the CI Replay checker.

Comment thread Generals/Code/GameEngine/Include/Common/Recorder.h Outdated
@xezon xezon changed the title fix(memory): Fix memory leak for RecorderClass::m_crcInfo fix(memory): Fix memory leak of RecorderClass::m_crcInfo May 20, 2026
@xezon xezon changed the title fix(memory): Fix memory leak of RecorderClass::m_crcInfo fix(recorder): Fix memory leak of RecorderClass::m_crcInfo May 20, 2026
@xezon xezon merged commit 842c7a5 into TheSuperHackers:main May 20, 2026
17 checks passed
@Caball009 Caball009 deleted the fix_memory_leak_crcInfo branch May 20, 2026 22:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Fix Is fixing something, but is not user facing Gen Relates to Generals Memory Is memory related Minor Severity: Minor < Major < Critical < Blocker ZH Relates to Zero Hour

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants