Skip to content

[ZH] Minor memory corruption and leak fixes#716

Closed
helmutbuhler wants to merge 8 commits into
TheSuperHackers:mainfrom
helmutbuhler:mem_fixes_sh
Closed

[ZH] Minor memory corruption and leak fixes#716
helmutbuhler wants to merge 8 commits into
TheSuperHackers:mainfrom
helmutbuhler:mem_fixes_sh

Conversation

@helmutbuhler

Copy link
Copy Markdown

4 easy fixes:

  • Fix wrong iterator usage (VS22 would crash, VC6 doesn't care)
  • Reading of uninitialized stack memory (see comment)
  • A drawable was potentially leaked by wrong copypasta code
  • A drawable was used after freeing it

I tested all changes by checking some replays for mismatches.

Note about the second fix: You can check that it reads that uninitialized memory by setting all bits to one:
memset(approachBones, -1, sizeof(approachBones));
It will then mismatch on the golden replay 1. It seems we are lucky that that memory is all 0 on retail version.

About the last fix: I'm not sure what drawable the retail binary is accessing when using the just freed drawable, but I have a replay which uses that code path and the fix works fine there.

This reverts commit 3d4b5c7.

Revert "[GEN] Backport BlurTime functionality in WW3D2's ParticleBufferClass (#711)"

This reverts commit bcfe2e4.

Revert "[CORE] Move matchbot tool to Core (#706)"

This reverts commit 61ac7bd.
@Mauller Mauller added Minor Severity: Minor < Major < Critical < Blocker Gen Relates to Generals ZH Relates to Zero Hour Stability Concerns stability of the runtime labels Apr 20, 2025

@Mauller Mauller left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

They look good overall. But you need to rebase this PR and only have it include commits related to your changes.

I would also pullout the Iterator changes into their own PR and include similar generals related changes as these won't affect runtime. But the other changes need investigating first.

if (items)
{
for (ContainedItemsList::const_iterator it = items->begin(); *it != NULL && numKilled < d->m_garrisonHitKillCount; )
for (ContainedItemsList::const_iterator it = items->begin(); it != items->end() && numKilled < d->m_garrisonHitKillCount; )

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Looks genuine to me, should not affect VC6 as the original behaviour was fine for STLPort.

If you can replicate this and the other iterator fix to generals as well, that would be great.


// TheSuperHackers @fix helmutbuhler 04/19/2025
// This originally mistakenly assigned to m_orbitToTargetBeamID and thus caused a leak.
m_groundToOrbitBeamID = INVALID_DRAWABLE_ID;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Looks legitimate to me, will just need to check against VC6 that we don't cause a mismatch by this change,

TheThingFactory->newDrawable( tTemplate );
// TheSuperHackers @bugfix helmutbuhler 04/13/2025
// draw was originally not assigned here and potentially caused memory corruption
draw = TheThingFactory->newDrawable( tTemplate );

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Looks genuine, might need checking again against VC6 since it could cause a mismatch even though it fixes behaviour.

@xezon

xezon commented Apr 20, 2025

Copy link
Copy Markdown

Please make this 4 pull requests and replicate them in Generals.

@Mauller

Mauller commented Apr 20, 2025

Copy link
Copy Markdown

I have pulled this PR apart into 4 seperate pull requests. It should get closed when the iterator usage PR is merged.

@helmutbuhler

Copy link
Copy Markdown
Author

Thank you, I'll close this right away

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Gen Relates to Generals Minor Severity: Minor < Major < Critical < Blocker Stability Concerns stability of the runtime ZH Relates to Zero Hour

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants