XAudio2: stale voice-pointer reuse (ABA) when an IXAudio2 engine is released with live voices #325
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
Imported from ivall/xcl. Originally posted by mastrr9 on 2026-11-23T23:29:55Z.
Static audit of
crates/xcl/src/hle/xaudio2.rsonmain(85bdf21) found a voice-pointer reuse (ABA) hazard acrosscreate_source_voiceanddestroy_voice(xaudio2.rs:791-796, 919-924, 1148-1168):DECODED_VOICESandXMAstore entries keyed by raw voice address (voice as usize), and entries are only removed insidedestroy_voice.IXAudio2engine without explicitly callingDestroyVoiceon every source voice first (Windows XAudio2 tears down child voices internally when the engine is destroyed), ourdestroy_voicevtable hook never runs for those voices.DECODED_VOICES/XMA(andDECODED_LIVE_COUNTstays incremented, plusDecodedCallbackleaks).CreateSourceVoicefor a plain PCM voice receives a reused heap address from Windows,create_source_voicedoes not evict stale entries forvoice, so subsequentSubmitSourceBuffercalls on that plain PCM voice are intercepted and fed into the stale Opus/XMA decoder (causing silence or garbled audio).Suggested fix:
On every successful
CreateSourceVoice(both the decoded-voice and plain-PCM paths), evict any stale entry forvoice as usizefromXMAandDECODED_VOICES(decrementingDECODED_LIVE_COUNTand dropping any stale callback handle if present) before inserting the new voice (or returning for plain PCM).Not tested: on Windows (static code audit on macOS; no game files).
AI use: Audited with Antigravity (Gemini 4 Neon) and Claude Sonnet 5.5 (static code review only).
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T00:24:37Z.
I'll take this. Plan: factor the decoded-voice teardown (
DECODED_VOICESremove +DECODED_LIVE_COUNTdecrement +live_buffersclear + callback box drop) into helpers shared bydestroy_voiceand a newevict_voice(voice); callevict_voiceon the address Windows hands back inCreateSourceVoiceon both the decoded path (create_decoded_voice) and the plain/silent path, before the new entry is inserted. Unit test inserts a staleXMA+DECODED_VOICESentry at a fake voice address, evicts, and checks both maps and the live count. Windows test suite on RTX 3060 Ti + Ryzen 9 7900X iGPU; smoke run on the retail title per CONTRIBUTING.