Two call sites build a PCWSTR from a temporary HSTRING. The temporary drops at the ;, so the PCWSTR points at freed heap memory before the Win32 call reads it.
src/api.rs:370 in DeviceEnumerator::get_device:
let w_id = PCWSTR::from_raw(HSTRING::from(device_id).as_ptr());
let immdevice = unsafe { self.enumerator.GetDevice(w_id)? };
src/api.rs:1903 in set_echo_cancellation_render_endpoint:
PCWSTR::from_raw(HSTRING::from(endpoint_id).as_ptr())
Fix, bind the HSTRING so it outlives the FFI call:
let w_id = HSTRING::from(device_id);
let immdevice = unsafe { self.enumerator.GetDevice(&w_id)? };
Symptom we hit: get_device(id) returns success, then Activate(IID_IAudioClient, ...) fails with 0x80070002.
Env: wasapi 0.23.0, windows 0.62.2, Windows 11 26200, rustc stable.
Happy to send a PR.
Two call sites build a
PCWSTRfrom a temporaryHSTRING. The temporary drops at the;, so thePCWSTRpoints at freed heap memory before the Win32 call reads it.src/api.rs:370inDeviceEnumerator::get_device:src/api.rs:1903inset_echo_cancellation_render_endpoint:Fix, bind the HSTRING so it outlives the FFI call:
Symptom we hit:
get_device(id)returns success, thenActivate(IID_IAudioClient, ...)fails with0x80070002.Env: wasapi 0.23.0, windows 0.62.2, Windows 11 26200, rustc stable.
Happy to send a PR.