Repository navigation
HLE: leave a released-out COM count at zero - #31
AndyLatimer wants to merge 2 commits into
Conversation
Release at a count of 0 in dstorage, gameinput, media and xg did fetch_sub(1) - 1: a panic in debug builds and, in release builds, a second free. A shared release_ref now keeps the count at 0, frees nothing and warns. One test per module.
|
Thanks for this. One thing to be aware of: in all four modules, when the count reaches 0 the object is freed in the same call, so a title releasing "once too often" makes its next |
|
Tested
AI-assisted (DeepSeek V4.1 Flash coding agent). |
|
Verified
AI-assisted. |
# Conflicts: # crates/victory-hle/src/modules/dstorage.rs
|
Thanks for the reviews. The description now states the scope accurately: this keeps our own release paths from underflowing or double-freeing at a count of 0, but a title's extra Release after the object was freed is still a use-after-free that this does not catch. The branch is merged with current main ( |
|
Tested the new head
No game data used. |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
In
dstorage,gameinput,mediaandxg,Releasecomputed the new COM reference count asrefs.fetch_sub(1, Ordering::AcqRel) - 1. When the count is already 0, that subtraction underflowsu32: a panic in debug builds, and in release builds a wrapped count with a second free on the next call that reaches 0.This adds a shared
release_refhelper incrates/victory-hle/src/modules/mod.rs, built onfetch_update+checked_sub(1). At a count of 0 it leaves the count at 0, logs a warning and returnsNone, and the caller frees nothing.Scope (thanks to the review): these objects are freed in the call that takes their count to 0. A title that releases once too often therefore makes its next
Releaseread freed memory beforerelease_refruns, and this change does not detect or fix that use-after-free. What it does guarantee is that our own release paths never underflow or double-free on a count of 0. The tests reach that state by setting the count to 0 on a live object. Catching real double releases would need a freed-object marker (or a quarantine for released objects), which is not part of this PR.Testing
main(d2a4bae) in79bb95e. The conflict was two tests added at the end ofdstorage's test module; both are kept.cargo test --workspace: 268 passed, 4 ignored (need external files). This includes 4 regression tests, one per module.cargo clippy -p victory-hle --all-targets: no new warnings (thexmem.rsone is onmain).cargo xtask policy: pass.🤖 Generated with Claude Code