Audio heap: a block freed under the decoder's slice stays in memory until let go (#230) #248
No reviewers
Labels
No labels
accessibility
already-solved
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
merged
needs-decision
needs-game-run
needs-rebase
not-merged
nvidia
obsolete
question
security
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/avatarmanz--VIctory-7900XTX!248
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-248"
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?
@sharan104 on GitHub · 2026-11-26 12:41 UTC · original
sharan104:fix/230-apu-free-deferred→main· +71 −3 · 1 files · 1 commits · openFixes #230.
heap_bytesreturns slices of heap blocks whose lifetime isn't tied to the heap. The XMA decoder writes output blocks and reads input packets through them, whileheap_freetook the block out and deallocated it at once. So a title that freed a voice's ring or input while the voice was still decoding had the decoder write into freed host memory. That's a title bug, which corrupts memory on the console too, so this is insurance, as the issue says.The issue's sketch drains the deferred frees on the decoder thread.
pump()also runs on other threads, though (the tests' passes), and the diagnosticsdump_inputtakes a slice too. So this uses a holder count instead:Holding(an RAII guard) is held around each XMA pass and arounddump_input's read.heap_freestill removes the block and gives its device range back immediately.ApuFree's range behaviour is unchanged, and no new slice can reach the block. It deallocates only when nothing holds slices; otherwise it pushes(ptr, layout)toFREED.FREED. It looks at the count again underFREED's lock, the same lock frees push under. So a holder that began after the first look, and may hold a slice of a block freed after it began, keeps that block until it lets go.SeqCston the count. TheHEAPmutex orders the removal against any later lookup, so a holder that starts after a block was removed can't reach it.Test:
a_block_freed_under_a_held_slice_stays_until_let_go. It allocates, takes a slice under aHoldingand frees the block. It then checks that the block is gone from the heap, is still inFREED, and can still be written through the slice. After the holder lets go, the block is released unless another test's pass still holds slices; that last check is written to tolerate tests running in parallel.Results:
cargo test -p victory-hle --lockedpassed 10 times out of 10 (156 tests each run).--all-features --test-threads=1.cargo clippy -p victory-hle --all-targets --locked --no-deps -- -D warningsis clean, with and without--all-features.🤖 Generated with Claude Code
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.