HLE: reject null output pointers in DirectStorage factory and release FidelityFX DLL on load failure #2578

Closed
reeledMarek wants to merge 1 commit from upstream-pr/2580 into main
reeledMarek commented 2026-11-25 16:09:07 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by reeledMarek on 2026-11-25T16:09:07Z.


Summary

Fixes two resource leaks on error paths in victory-hle:

  1. dstorage.rs (create_status_array, create_queue): validates out.is_null() upfront and returns E_INVALIDARG before heap-allocating Instance<StatusArray> / Instance<Queue> or permanently inserting a Lane into scheduler().
  2. fidelityfx.rs (load): guards the HMODULE returned by LoadLibraryExW with an RAII Drop wrapper (FreeLibrary), disarming it only when Ok((host, versions)) succeeds, so failed export lookups, missing host GPU, or failed versions() queries do not leak the loaded DLL handle.

Testing

  • Added synthetic unit test null_out_is_rejected_before_creating_status_array_or_queue in dstorage.rs.
  • cargo test -p xtask --locked (6/6 passed).
  • Full Windows build, clippy, and test suite verified via GitHub Actions CI.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6608593397 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2580). Originally posted by [reeledMarek](https://github.com/reeledMarek) on 2026-11-25T16:09:07Z. --- ### Summary Fixes two resource leaks on error paths in `victory-hle`: 1. **`dstorage.rs` (`create_status_array`, `create_queue`):** validates `out.is_null()` upfront and returns `E_INVALIDARG` before heap-allocating `Instance<StatusArray>` / `Instance<Queue>` or permanently inserting a `Lane` into `scheduler()`. 2. **`fidelityfx.rs` (`load`):** guards the `HMODULE` returned by `LoadLibraryExW` with an RAII `Drop` wrapper (`FreeLibrary`), disarming it only when `Ok((host, versions))` succeeds, so failed export lookups, missing host GPU, or failed `versions()` queries do not leak the loaded DLL handle. ### Testing - Added synthetic unit test `null_out_is_rejected_before_creating_status_array_or_queue` in `dstorage.rs`. - `cargo test -p xtask --locked` (6/6 passed). - Full Windows build, clippy, and test suite verified via GitHub Actions CI.
Marvisak commented 2026-11-25 23:06:08 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T22:18:42Z.


Automated triage for the maintainers.

Proposed close: no practical value. Both changes cover cases that do not happen or cost nothing:

  • dstorage.rs: create_status_array and create_queue already return E_INVALIDARG for a null out, through xgameruntime::put. The new early checks only avoid one small allocation (and one idle lane) for a call that passes no out pointer, which the title does not do. The test checks the error code, which main already returns.
  • fidelityfx.rs: load runs once and only on the user's own FidelityFX DLL. On failure, keeping the module loaded costs nothing. Freeing it after versions() has already called ffxQuery on the host device is less safe than leaving it loaded, because the DLL may hold state tied to that device.

CI (check) passes and it merges cleanly. This PR will be closed in 48 hours unless the author pushes a change (for example a real path where the title passes a null out) or a maintainer removes the triage: proposed close label.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7176203822 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2580#issuecomment-7176203822). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T22:18:42Z. --- <!-- victory-triage v1 head=687e82b69a3b6bd2dc7ecff29c5c1a79acf917af verdict=proposed-close at=2026-11-25T22:18:35Z --> Automated triage for the maintainers. **Proposed close: no practical value.** Both changes cover cases that do not happen or cost nothing: - `dstorage.rs`: `create_status_array` and `create_queue` already return `E_INVALIDARG` for a null `out`, through `xgameruntime::put`. The new early checks only avoid one small allocation (and one idle lane) for a call that passes no out pointer, which the title does not do. The test checks the error code, which `main` already returns. - `fidelityfx.rs`: `load` runs once and only on the user's own FidelityFX DLL. On failure, keeping the module loaded costs nothing. Freeing it after `versions()` has already called `ffxQuery` on the host device is less safe than leaving it loaded, because the DLL may hold state tied to that device. CI (`check`) passes and it merges cleanly. This PR will be closed in 48 hours unless the author pushes a change (for example a real path where the title passes a null out) or a maintainer removes the `triage: proposed close` label. --- _Generated by [Claude Code](https://claude.ai/code)_
upstream-sync closed this pull request 2026-11-26 06:02:32 +00:00
reeledMarek commented 2026-11-26 06:03:47 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by reeledMarek on 2026-11-26T05:43:34Z.


Closing per triage: xgameruntime::put already returns E_INVALIDARG on a null out pointer, and unloading the FidelityFX DLL after ffxQuery is less safe than keeping it loaded. Thanks for the review!

<!-- greyfinch-sync:Marvisak/VIctory:comment:7183748971 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2580#issuecomment-7183748971). Originally posted by [reeledMarek](https://github.com/reeledMarek) on 2026-11-26T05:43:34Z. --- Closing per triage: `xgameruntime::put` already returns `E_INVALIDARG` on a null out pointer, and unloading the FidelityFX DLL after `ffxQuery` is less safe than keeping it loaded. Thanks for the review!

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!2578
No description provided.