XGameRuntime: avoid leaking Mount handles in mount_with_ui_async #1242

Open
github-bot wants to merge 1 commit from github-bot/gh-1242 into main AGit
Owner

@⁠b3IKK on GitHub · 2026-11-24 13:39 UTC · original
b3IKK:xgameruntime/mount-with-ui-async-leak → main · +54 −7 · 2 files · 1 commits · open

mount_with_ui_async called XPackageMount (allocating Box<Mount>) before begin_with validated the XAsyncBlock or scheduled work. If b was null (E_INVALIDARG) or its task queue was already terminated (E_ABORT), the allocated Mount handle was never returned to the caller and leaked permanently.

This copies the optional package identifier and performs XPackageMount inside the begin_with work closure so Mount is only allocated when the async work runs.

What is in it

  • crates/xcl/src/hle/xgameruntime/api.rs: move XPackageMount inside the begin_with work closure in mount_with_ui_async; add unit test mount_with_ui_async_does_not_leak_mount_on_invalid_or_aborted_call.
  • crates/xcl/src/hle/xgameruntime/mod.rs: add #[cfg(test)] LIVE_MOUNTS counter in XPackageMount / XPackageCloseMountHandle for the leak test.

This is now the only PR from this account that changes mount_with_ui_async: the mount part was taken out of #1610 (#1607, group D68), so the two do not compete for the same lines.

Tested

  • hardware (GPU + driver, CPU), Windows build, Rust version, debug / release: NVIDIA GeForce RTX 5080 (driver 32.0.16.1088), AMD Ryzen 9 9950X3D, Windows 11 10.0.26300, Rust 1.100.0 (stable-x86_64-pc-windows-msvc), DXC 1.9.2609.5, debug (scripts/test.ps1) and release (scripts/smoke.ps1)
  • .\scripts\test.ps1 (cargo build --workspace + cargo test --workspace -- --test-threads=4): 994 passed, 0 failed, 45 ignored (SKIPPED: the wave64 / direct-DXIL per-lane tests that need 64-lane hardware or a semantics mode this adapter refuses, no heap windows, and cannot disable the driver cache (Windows Developer Mode is required))
  • cargo test -p xcl --lib -- mount_with_ui_async: 1 passed, 0 failed. With mount_with_ui_async put back to main's version and the test kept: 0 passed, 1 failed — Mount leaked on null XAsyncBlock.

Regression run

main (80f4819, clean tree, no local changes):

xcl-smoke v1
commit: 80f4819098e921f2e1ab371144d4832f68ffedd6
gpu: NVIDIA GeForce RTX 5080
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1638 (PresentX 1638)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 17779 MB

PR (7124d1e, clean tree, no local changes):

xcl-smoke v1
commit: 7124d1efab59ad2cadbecee8c95a356dfa6188b4
gpu: NVIDIA GeForce RTX 5080
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1643 (PresentX 1643)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 18020 MB

Not tested

  • a real title calling mount_with_ui_async with a terminated queue (the test builds that call)
  • AMD GPUs and native wave64 hardware
  • other titles (Minecraft Preview, Unicorn Overlord, Fortnite, XDefiant) and Linux / Wine

AI use

  • OpenCode, Claude Fable 5.2: audited xgameruntime/api.rs, wrote the fix and the regression test (and confirmed it fails with the old function), rebased onto 80f4819, ran the test suite and the scripts/smoke.ps1 runs, and drafted this PR description.
**@⁠b3IKK** on GitHub · 2026-11-24 13:39 UTC · [original](https://github.com/xcl-dev/xcl/pull/1242) `b3IKK:xgameruntime/mount-with-ui-async-leak` → `main` · +54 −7 · 2 files · 1 commits · open `mount_with_ui_async` called `XPackageMount` (allocating `Box<Mount>`) before `begin_with` validated the `XAsyncBlock` or scheduled work. If `b` was null (`E_INVALIDARG`) or its task queue was already terminated (`E_ABORT`), the allocated `Mount` handle was never returned to the caller and leaked permanently. This copies the optional package identifier and performs `XPackageMount` inside the `begin_with` work closure so `Mount` is only allocated when the async work runs. **What is in it** - `crates/xcl/src/hle/xgameruntime/api.rs`: move `XPackageMount` inside the `begin_with` work closure in `mount_with_ui_async`; add unit test `mount_with_ui_async_does_not_leak_mount_on_invalid_or_aborted_call`. - `crates/xcl/src/hle/xgameruntime/mod.rs`: add `#[cfg(test)]` `LIVE_MOUNTS` counter in `XPackageMount` / `XPackageCloseMountHandle` for the leak test. This is now the only PR from this account that changes `mount_with_ui_async`: the mount part was taken out of #1610 (#1607, group D68), so the two do not compete for the same lines. **Tested** - hardware (GPU + driver, CPU), Windows build, Rust version, debug / release: NVIDIA GeForce RTX 5080 (driver 32.0.16.1088), AMD Ryzen 9 9950X3D, Windows 11 10.0.26300, Rust 1.100.0 (`stable-x86_64-pc-windows-msvc`), DXC 1.9.2609.5, debug (`scripts/test.ps1`) and release (`scripts/smoke.ps1`) - `.\scripts\test.ps1` (`cargo build --workspace` + `cargo test --workspace -- --test-threads=4`): 994 passed, 0 failed, 45 ignored (SKIPPED: the wave64 / direct-DXIL per-lane tests that need 64-lane hardware or a semantics mode this adapter refuses, `no heap windows`, and `cannot disable the driver cache (Windows Developer Mode is required)`) - `cargo test -p xcl --lib -- mount_with_ui_async`: 1 passed, 0 failed. With `mount_with_ui_async` put back to `main`'s version and the test kept: 0 passed, 1 failed — `Mount leaked on null XAsyncBlock`. **Regression run** main (`80f4819`, clean tree, no local changes): ``` xcl-smoke v1 commit: 80f4819098e921f2e1ab371144d4832f68ffedd6 gpu: NVIDIA GeForce RTX 5080 title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1638 (PresentX 1638) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 17779 MB ``` PR (`7124d1e`, clean tree, no local changes): ``` xcl-smoke v1 commit: 7124d1efab59ad2cadbecee8c95a356dfa6188b4 gpu: NVIDIA GeForce RTX 5080 title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1643 (PresentX 1643) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 18020 MB ``` **Not tested** - a real title calling `mount_with_ui_async` with a terminated queue (the test builds that call) - AMD GPUs and native wave64 hardware - other titles (Minecraft Preview, Unicorn Overlord, Fortnite, XDefiant) and Linux / Wine **AI use** - OpenCode, Claude Fable 5.2: audited `xgameruntime/api.rs`, wrote the fix and the regression test (and confirmed it fails with the old function), rebased onto `80f4819`, ran the test suite and the `scripts/smoke.ps1` runs, and drafted this PR description.
mount_with_ui_async called XPackageMount (allocating Box<Mount>) before
begin_with validated the XAsyncBlock or scheduled work. If the
XAsyncBlock was null (E_INVALIDARG) or its task queue was already
terminated (E_ABORT), the allocated Mount handle was never returned to
the caller and leaked permanently.

Copy the optional package identifier and perform XPackageMount inside
the begin_with work closure so Mount is only allocated when the async
work actually runs.

Assisted-by: OpenCode (Claude Fable 5.2)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:48:13 +00:00
Author
Owner

@⁠dcastell1 on GitHub · 2026-11-24 13:45 UTC · original

Verified on Windows 11 10.0.26300, NVIDIA GeForce RTX 5090 (driver 621.24), Rust 1.100.0 MSVC 14.44.35207, debug build, on main@930e8b4 (baseline 751 passed, 0 failed, 41 ignored on this box):

patch -p1 < this PR            # clean, no fuzz
cargo test --workspace -- --test-threads=4
752 passed; 0 failed; 41 ignored   (exit 0)

One more than the baseline; the XGameRuntime mount-handle leak fix is exercised and green.

Tree restored afterwards (full diff against a clean checkout), hardware adapter, no Wine, no game data. AI-assisted (opencode): applied the patch to a built tree, ran the suite, reverted it.

**@⁠dcastell1** on GitHub · 2026-11-24 13:45 UTC · [original](https://github.com/xcl-dev/xcl/pull/1242#issuecomment-7133287903) Verified on Windows 11 10.0.26300, NVIDIA GeForce RTX 5090 (driver 621.24), Rust 1.100.0 MSVC 14.44.35207, debug build, on `main@930e8b4` (baseline **751 passed, 0 failed, 41 ignored** on this box): ``` patch -p1 < this PR # clean, no fuzz cargo test --workspace -- --test-threads=4 752 passed; 0 failed; 41 ignored (exit 0) ``` One more than the baseline; the XGameRuntime mount-handle leak fix is exercised and green. Tree restored afterwards (full diff against a clean checkout), hardware adapter, no Wine, no game data. AI-assisted (opencode): applied the patch to a built tree, ran the suite, reverted it.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-24 14:02 UTC · original

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib lib xgameruntime: 74 passed, 0 failed.

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-24 14:02 UTC · [original](https://github.com/xcl-dev/xcl/pull/1242#issuecomment-7133729232) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - cargo test -p xcl --lib lib xgameruntime: 74 passed, 0 failed. Thanks!
Author
Owner

@⁠b3IKK on GitHub · 2026-11-25 00:14 UTC · original

Rebased onto 80f4819 (main had added a test at the same place in api.rs; both are kept) and re-ran: 994 passed, 0 failed, 45 ignored. This is now the only PR from this account that changes mount_with_ui_async: #1610 no longer does. Against main's function the test fails with Mount leaked on null XAsyncBlock. AI use: OpenCode, Claude Fable 5.2.

**@⁠b3IKK** on GitHub · 2026-11-25 00:14 UTC · [original](https://github.com/xcl-dev/xcl/pull/1242#issuecomment-7148308693) Rebased onto `80f4819` (`main` had added a test at the same place in `api.rs`; both are kept) and re-ran: 994 passed, 0 failed, 45 ignored. This is now the only PR from this account that changes `mount_with_ui_async`: #1610 no longer does. Against `main`'s function the test fails with `Mount leaked on null XAsyncBlock`. AI use: OpenCode, Claude Fable 5.2.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-26 04:32 UTC · original

Re-verification on RTX 3060 Ti (Windows 11), new head merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved.

Thanks!

— Devin

**@⁠DavidM1911** on GitHub · 2026-11-26 04:32 UTC · [original](https://github.com/xcl-dev/xcl/pull/1242#issuecomment-7182683686) Re-verification on RTX 3060 Ti (Windows 11), new head merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved. Thanks! — Devin
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1242/head:github-bot/gh-1242'
git switch 'github-bot/gh-1242'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1242'
git switch 'github-bot/gh-1242'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1242'
git switch 'github-bot/gh-1242'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1242'
git switch 'main'
git merge --squash 'github-bot/gh-1242'
git switch 'main'
git merge --ff-only 'github-bot/gh-1242'
git switch 'main'
git merge 'github-bot/gh-1242'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.