Loader: unload already-mapped title DLLs when a dependency fails #3054
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!3054
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3054"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@Dukestar69 on GitHub · 2026-11-26 05:37 UTC · original
Dukestar69:fix/loader-unload-dlls-on-error→main· +112 −3 · 2 files · 1 commits · openSummary
Unloads already-mapped title DLLs (calling
LoadedImage::unload, which removes them fromthreads::IMAGESand frees theirHMODULE) when loading a transitive or sibling dependency fails inmap_dll,load_title_dll, orload_title_dlls.Why
LoadedImageintentionally has noDropimplementation because mapped images stay live after being handed to the runtime. However:map_dll,load(&prepared, dirs.1)maps the DLL and registers it inthreads::IMAGESbefore recursively callingmap_imports(&image.info, ...). If any transitive dependency fails to read, prepare, or load,?droppedimagewithout unloading it.load_title_dllandload_title_dlls, if a later sibling or transitive dependency fails after earlier DLLs were already pushed intoloaded,?droppedloadedwithout unloading them.In both cases, those
HMODULEs remained permanently mapped in the process (keeping their cached.dllfiles locked on disk) and permanently registered inthreads::IMAGES, which is reachable at runtime viaLateDlls::loadif a dynamically loaded title DLL has a broken dependency.(Scoped to
map_dll/load_title_dll/load_title_dllsonly, with a separate integration test file — zero overlap with #1201, which handlesload()TLS redirect failure.)Verification
crates/victory-loader/tests/dll_unload_on_error.rs:load_title_dll_unloads_parent_when_dependency_fails(failed on63bcca4, passes with fix)load_title_dlls_unloads_earlier_siblings_when_later_dll_fails(failed on63bcca4, passes with fix)cargo test -p victory-loader -- --test-threads=1: all 41 tests passed (35 unit + 6 integration).cargo clippy -p victory-loader --all-targets -- -D warnings: clean.rustfmt --edition 2024 --check: clean.cargo xtask policy: 192 files ok.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
@Marvisak on GitHub · 2026-11-26 06:18 UTC · original
Automated triage for the maintainers.
Verdict: merge candidate. In
crates/victory-loader/src/windows.rs,map_dllnow unloads its own image when a dependency fails.load_title_dllandload_title_dllsunload, in reverse order, whatever was already pushed toloaded. Each image is unloaded exactly once on any error path: the parent unloads itself before returning, and earlier dependencies are inloaded. On these paths nothing has been bound or attached yet, becauseLateDlls::loadinapps/victory/src/run.rsbinds and attaches only afterload_title_dllreturnsOk, andload()maps prepared images that have no entry point. SoLoadedImage::unload's safety requirement holds. The runtime path that matters isLateDlls::load(a titleLoadLibrarywith a broken dependency). The two new integration tests show the leak through the locked cache file.CI: no check runs reported for this head (not run). It should run before merging.
Generated by Claude Code
@kotekompotek on GitHub · 2026-11-26 06:01 UTC · original · approved these changes
Verified: the failure path genuinely leaked — a transitive dep failing left the parent mapped for process life, and a later sibling failing leaked all earlier ones. The unload safety argument holds (imports are bound and entry points run only after full load); reverse order unloads dependents first. The synthetic-DLL tests are cleverly minimal and the cached-file deletion check is a real probe on Windows — a leaked mapping keeps the file undeletable.
@fuzeofficlal on GitHub · 2026-11-26 06:19 UTC · original · approved these changes
Verified at
8d6eddefon Windows 11 x64 (Rust 1.98.1 MSVC):map_dllandload_title_dll/load_title_dllsunwind paths: ifmap_importsfails afterload()maps a parent DLL,map_dllunloads the parent before pushing it toloaded, and the top-level entry points unwindloadedin reverse order (unload_all), avoiding bothHMODULEleaks and double-unloads.LoadedImage::unloadalso callscrate::threads::unmapped(self.base()), so no stale thread-notification entry remains.cargo test -p victory-loader --locked: 41 passed, 0 failed (including both newdll_unload_on_errortests).cargo clippy -p victory-loader --locked --all-targets -- -D warnings: clean.Looks good.
@futurepro62 on GitHub · 2026-11-26 19:41 UTC · original
NVIDIA full-suite run, to go with the reports above by fuzeofficlal, since none of them names a GPU run. Tested exact head
8d6edde(on its base63bcca4).Tested
dxil.dllfrom Windows SDK 10.0.26100 (the loader's default), debug.cargo build --workspace --locked, thencargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware: 868 passed, 0 failed, 10 ignored.load_title_dll_unloads_parent_when_dependency_fails,load_title_dlls_unloads_earlier_siblings_when_later_dll_fails.--skipleaves out tests that fail on main63bcca4on this card too, not because of this PR:heap_direct_texture_reads_mark_their_heap_indexends thevictory-shadertest process with0xc0000005(#2571), so without the skip the rest of that crate never reports;dynamic_slots_are_held_until_released,lists_share_a_table_and_copies_keep_their_viewsand the twostride_testshit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317);gathers_at_a_level_match_the_hardwarefails on lane 0 (#1744).Not tested
AI use
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.