Skip to content

Fix: Windows share worker crashed when it started capturing game sound - #109

Merged
AlxcBTW merged 1 commit into
mainfrom
fix/loopback-blob-free
Oct 27, 2026
Merged

AlxcBTW merged 1 commit into
mainfrom
fix/loopback-blob-free

Conversation

@fma-rc

@fma-rc fma-rc commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

On Windows the share worker aborted with heap corruption (0xc0000374) the first time a stream with game sound started, before any sound was captured.

The process loopback request (AUDIOCLIENT_ACTIVATION_PARAMS) lives on the stack and goes to ActivateAudioInterfaceAsync inside a VT_BLOB PROPVARIANT. In windows 0.62, PROPVARIANT clears itself on drop, so PropVariantClear handed the stack address to CoTaskMemFree. A backtrace in gdb shows PROPVARIANT::drop -> FreePropVariantArrayWorker -> RtlFreeHeap from loopback::capture. It happens on every path through activate, whatever the system answers.

The fix keeps the PROPVARIANT in ManuallyDrop. Nothing in it was ever ours to free.

tests/loopback.rs (Windows only) opens the capture of the test's own process three times and passes whether the machine has sound or not. Run on Windows Server 2025 (build 26100, x86_64-pc-windows-gnu): without the fix the test binary aborts with 0xc0000374; with it the test passes. With the fix, I captured a process playing a test file (peak -24 dBFS, RMS 0.035) in a signed-in session and ran it through the real host loop, jitter buffer, decoder and speakers for 60 s at three loss rates:

dropped sent/s lost late skipped played RMS played peak
0% 99.8 0 0 6 0.0349 0.065
5% 99.8 292 0 0 0.0337 0.076
20% 100.0 1179 0 0 0.0301 0.076

What plays matches the source level; the 6 skipped packets at 0% come from capture bursts after short stalls (2 to 5 gaps over 30 ms per minute).

Checks: cargo fmt --check, cargo clippy -D warnings (Linux workspace and the share worker for Windows), cargo test --workspace on Linux.

The activation request for process loopback capture lives on the stack and is
passed as a VT_BLOB PROPVARIANT. In windows 0.62 PROPVARIANT clears itself on
drop, so CoTaskMemFree ran on stack memory and the worker aborted with heap
corruption (0xc0000374) the first time a stream with game sound started.

Keep the PROPVARIANT in ManuallyDrop. The new Windows test opens the capture of
its own process three times; it aborts without the fix and passes with it.
@AlxcBTW
AlxcBTW merged commit 108232e into main Oct 27, 2026
13 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants