run: free the executable's bytes once its image is mapped #2071

Closed
github-bot wants to merge 1 commit from gh-pr/2071/head into gh-pr/2071/base
Owner

@⁠0xkn0wh3r3 on GitHub · 2026-11-25 04:22 UTC · original
0xkn0wh3r3:app/free-image-bytes-after-load → main · +5 −0 · 1 files · 1 commits · closed without merging

The problem

run held two copies of the title's executable in memory for the whole run, though neither is needed once the title is loaded. For Grand Theft Auto VI that held about 115 MB twice.

The mechanism: run reads the executable into memory (original) and prepares a patched copy of it for the loader (prepared, from victory_loader::prepare). It kept both until the title exited. The program runs from the image victory_loader::load maps, and neither buffer is read after that.

The fix

Both buffers are now dropped right after victory_loader::load (apps/victory/src/run.rs). The compiler checks that nothing uses them later. Nothing else changes.

Ported from fxceless/victory-fork (commit 578d459), where the two blocks were found in a run's memory map.

Testing

  • cargo build -p victory: the borrow checker confirms neither buffer is used after the load.
  • cargo test -p victory: all pass. cargo clippy -p victory --all-targets: clean.

Not covered

  • Not measured in a title run (no game data here); the sizes are from the fork's run.
**@⁠0xkn0wh3r3** on GitHub · 2026-11-25 04:22 UTC · [original](https://github.com/Marvisak/VIctory/pull/2071) `0xkn0wh3r3:app/free-image-bytes-after-load` → `main` · +5 −0 · 1 files · 1 commits · closed without merging ## The problem `run` held two copies of the title's executable in memory for the whole run, though neither is needed once the title is loaded. For Grand Theft Auto VI that held about 115 MB twice. The mechanism: `run` reads the executable into memory (`original`) and prepares a patched copy of it for the loader (`prepared`, from `victory_loader::prepare`). It kept both until the title exited. The program runs from the image `victory_loader::load` maps, and neither buffer is read after that. ## The fix Both buffers are now dropped right after `victory_loader::load` (`apps/victory/src/run.rs`). The compiler checks that nothing uses them later. Nothing else changes. Ported from fxceless/victory-fork (commit 578d459), where the two blocks were found in a run's memory map. ## Testing - `cargo build -p victory`: the borrow checker confirms neither buffer is used after the load. - `cargo test -p victory`: all pass. `cargo clippy -p victory --all-targets`: clean. ## Not covered - Not measured in a title run (no game data here); the sizes are from the fork's run.
`run` read the title's executable into memory and prepared a patched
copy of it for the loader, then kept both until the title exited: the
program runs from the image `victory_loader::load` maps, and neither
buffer is read after that. For Grand Theft Auto VI that held about
115 MB twice for the whole run.

Both are now dropped right after the load. The compiler checks that
nothing uses them later.

Ported from fxceless/victory-fork (commit 578d459), where the two
blocks were found in a run's memory map.

Co-authored-by: fxceless <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:53:56 +00:00
github-bot closed this pull request 2026-11-26 04:53:56 +00:00
Author
Owner

@⁠0xkn0wh3r3 on GitHub · 2026-11-25 06:35 UTC · original

@catminou4: relocations are applied before the drop. \victory_loader::load` writes the prepared bytes to a file and maps it with `LoadLibraryExW`, and Windows applies the relocations while mapping it. The loaded image keeps its own copy of the image info and borrows neither buffer, which the compiler confirms. Once `load` returns, the file's bytes and the prepared copy aren't read again, so they're dropped right there.

**@⁠0xkn0wh3r3** on GitHub · 2026-11-25 06:35 UTC · [original](https://github.com/Marvisak/VIctory/pull/2071#issuecomment-7154952302) `@catminou4: relocations are applied before the drop. \`victory_loader::load\` writes the prepared bytes to a file and maps it with \`LoadLibraryExW\`, and Windows applies the relocations while mapping it. The loaded image keeps its own copy of the image info and borrows neither buffer, which the compiler confirms. Once \`load\` returns, the file's bytes and the prepared copy aren't read again, so they're dropped right there.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 10:26 UTC · original · edited 2026-11-25 15:55 UTC

Automated triage for the maintainers.

This pull request no longer merges cleanly into main (conflicts in apps/victory/src/run.rs). It will be reviewed once it is rebased onto the current main. The earlier verdict (merge-candidate) was for an older state of main.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 10:26 UTC · [original](https://github.com/Marvisak/VIctory/pull/2071#issuecomment-7159703204) · edited 2026-11-25 15:55 UTC <!-- victory-triage v1 head=189c1cadfa9731b415328ac4cd808b6b2a92060c verdict=needs-rebase at=2026-11-25T15:57:30Z --> Automated triage for the maintainers. This pull request no longer merges cleanly into `main` (conflicts in `apps/victory/src/run.rs`). It will be reviewed once it is rebased onto the current `main`. The earlier verdict (merge-candidate) was for an older state of `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠0xkn0wh3r3 on GitHub · 2026-11-25 18:51 UTC · original

Closing: upstream 5c4c685 (the exe's bytes are dropped once the image is mapped) does exactly this. The read is passed straight to victory_loader::prepare, and prepared is dropped right after load.

**@⁠0xkn0wh3r3** on GitHub · 2026-11-25 18:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/2071#issuecomment-7171490847) Closing: upstream 5c4c685 (the exe's bytes are dropped once the image is mapped) does exactly this. The read is passed straight to `victory_loader::prepare`, and `prepared` is dropped right after `load`.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2071
No description provided.