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

Closed
0xkn0wh3r3 wants to merge 1 commit from upstream-pr/2071 into main
0xkn0wh3r3 commented 2026-11-25 04:22:44 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by 0xkn0wh3r3 on 2026-11-25T04:22:44Z.


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.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6597154993 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2071). Originally posted by [0xkn0wh3r3](https://github.com/0xkn0wh3r3) on 2026-11-25T04:22:44Z. --- ## 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.
catminou4 commented 2026-11-25 05:05:57 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T04:26:34Z.

Review: COMMENTED


Static review only: apps/victory is Windows-only (Win32/windows_sys) — nothing compiles or runs on macOS; source review of the diff.

Executable bytes freed once its image is mapped — memory-footprint fix on the launcher path; check the unmap ordering against PE relocation fixups.

<!-- greyfinch-sync:Marvisak/VIctory:review:6051851535 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2071#pullrequestreview-6051851535). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T04:26:34Z. **Review:** COMMENTED --- Static review only: apps/victory is Windows-only (Win32/windows_sys) — nothing compiles or runs on macOS; source review of the diff. Executable bytes freed once its image is mapped — memory-footprint fix on the launcher path; check the unmap ordering against PE relocation fixups.
DenRakEiw commented 2026-11-25 05:05:57 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T04:41:46Z.

Review: APPROVED


Verified locally merged onto origin/main (940d32f, Windows 11 x64, Rust 1.98.1 MSVC):

  • cargo test -p victory — 12 passed, 0 failed
  • cargo clippy -p victory --all-targets — 0 warnings
  • cargo xtask policy — ok (183 files ok)

Clean drop of raw executable bytes immediately after mapping the image. Looks good.

AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6051959404 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2071#pullrequestreview-6051959404). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-25T04:41:46Z. **Review:** APPROVED --- Verified locally merged onto `origin/main` (`940d32f`, Windows 11 x64, Rust 1.98.1 MSVC): - `cargo test -p victory` — 12 passed, 0 failed - `cargo clippy -p victory --all-targets` — 0 warnings - `cargo xtask policy` — ok (`183 files ok`) Clean drop of raw executable bytes immediately after mapping the image. Looks good. AI-assisted (Gemini 4 Neon).
0xkn0wh3r3 commented 2026-11-25 07:03:20 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by 0xkn0wh3r3 on 2026-11-25T06:35:34Z.


@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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7154952302 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2071#issuecomment-7154952302). Originally posted by [0xkn0wh3r3](https://github.com/0xkn0wh3r3) on 2026-11-25T06:35:34Z. --- `@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.
Marvisak commented 2026-11-25 11:05:21 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T10:26:41Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7159703204 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2071#issuecomment-7159703204). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T10:26:41Z. --- <!-- 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)_
upstream-sync closed this pull request 2026-11-25 19:04:56 +00:00
0xkn0wh3r3 commented 2026-11-25 19:06:38 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by 0xkn0wh3r3 on 2026-11-25T18:51:08Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7171490847 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2071#issuecomment-7171490847). Originally posted by [0xkn0wh3r3](https://github.com/0xkn0wh3r3) on 2026-11-25T18:51:08Z. --- 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

Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!2069
No description provided.