Repository navigation
Description
Summary
Use-after-free on the ASIO SDK's global theAsioDriver pointer when a device
fails the capability check. On current main, a device that fails
CheckDeviceCapabilities() during ASIO re-init can leave a dangling global
pointer that a later re-init dereferences. Symptoms are inconsistent — hang,
crash, or silent corruption — which matches the reports in #872 and #305.
Context
- Jamulus process doesn't get killed if you select a device with wrong sample rate (ASIO4ALL) #872 (closed 2021) reported the "process doesn't get killed / ASIO4ALL red
cross lockout" symptom; the root cause was not identified then. - Discovered as part of the Investigate Windows Hang if using ASIO4ALL especially #3779 investigation (Windows hang with ASIO4ALL),
in which Jamulus process doesn't get killed if you select a device with wrong sample rate (ASIO4ALL) #872's defect is one of several distinct problems.
Evidence (mcfnord, on Windows — issue #3779 comment 5224437188)
One honest caveat up front: this measurement was done with a synthetic test
driver that deliberately fails the capability check, not with ASIO4ALL on real
hardware. With that said:
- This is a use-after-free, not a leak:
ASIOExit()is effectively
removeCurrentDriver()+theAsioDriver = 0. The current failure branch
only does the first of those. - Outcome is driver-dependent: ASIO4ALL's driver object is static in its
DLL and survives the COM release (→ hang / lockout); Focusrite USB
ASIO's object is heap-allocated, so the next call faults (0xC0000005). - With the synthetic driver, the stock build (
4d142945) made seven ASIO
calls on the freed object; withASIOExit(), zero.
How to reproduce
The reliable repro we have is with a synthetic driver that fails
CheckDeviceCapabilities() on demand. On real Windows hardware with ASIO4ALL
this is our best guess at hitting the same path — it is unverified:
- Select a device that fails the capability check (e.g. one that does not
support the required sample rate) while a valid device is also available. - Trigger re-init (e.g. change the audio device in the client settings).
- Re-select the previous working device.
The failure branch is hit at CSound::LoadAndInitializeDriver()
(src/sound/asio/sound.cpp) — CheckDeviceCapabilities() fails, the driver is
released via asioDrivers->removeCurrentDriver(), and the global
theAsioDriver pointer is left dangling. A subsequent re-init dereferences it.
Proposed fix
In CSound::LoadAndInitializeDriver() (src/sound/asio/sound.cpp), the
CheckDeviceCapabilities() failure branch should call ASIOExit() instead
of asioDrivers->removeCurrentDriver(), so the global pointer is nulled. The
ASIOInit()-failed branch is left alone — from reading the ASIO SDK it resets
the global pointer on that path, though I haven't instrumented it to be sure.
A ready patch exists in fork PR ann0see/jamulus#286 (one-line change + comment),
reproducing the 7-vs-0 result. This issue is opened to track the defect so the
fix is not lost if the fork PR is never reopened upstream.
Requested actions
- Review whether the failure branch should use
ASIOExit(). - If agreed, apply the fix on
main(a small, low-risk change).
⚠️ AI-generated issue — please verify
- This text is AI generated, may be wrong, and may contain inaccuracies.
- The hardware verification described below was performed by a human with an AI agent
(mcfnord, on Windows).
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsTriage
Activity
ann0see commentedon Aug 8, 2026
Opened to track the capability check potential bug.
ann0see commentedon Aug 8, 2026
Very brief diff idea (for the fix in this issue)
In
CSound::LoadAndInitializeDriver()(src/sound/asio/sound.cpp), theCheckDeviceCapabilities()failure branch:The idea is that
ASIOExit()closes the session and nulls the SDK globaltheAsioDriver, preventing the use-after-free. This is just an idea and maynot be correct — e.g. the exact return/error path may differ on current
main, orASIOExit()may have side effects the branch should avoid.[-]ASIO driver use-after-free on failed device capability check (ASIO4ALL lockout / process won't exit)[/-][+]ASIO driver use-after-free when a device fails the capability check[/+]mcfnord commentedon Aug 12, 2026
🤖 AI: The
ASIOExit()idea splits into an in-tree half that checks out and an SDK half that cannot be checked from this repo. The routine loads the selected driver by name, then reaches the onlyASIOInit()call anywhere in this file, and the path directly beneath it returns early with a bareremoveCurrentDriver()when that initialization fails — correct, because nothing was initialized at that point. The capability check that runs immediately afterwards, backed by the channel-requirement logic it delegates to, is reached only onceASE_OKhas come back, and yet its failure branch releases the driver through that same bareremoveCurrentDriver(). The normal teardown routine handling the identical situation does it the other way, callingASIOExit()before it releases the driver, while the driver enumeration inside the constructor never initializes one at all. Since thatASIOInit()is the file's only one, the capability-failure branch is the single place an initialized driver is released withoutASIOExit()— the branch to compare against the ASIO4ALL red-cross lockout described in #872 and the inconsistent crash-or-hang behaviour recorded in #305. The same re-init sequence already carries a second and independent hardening candidate in the stray-bufferSwitch()andASIOMutex-scope proposal filed as #3869, which touches the callback side rather than the release side. The SDK-internal half — thatASIOExit()nulls the global — is not verifiable from here, since the ASIO SDK is not vendored in this repo.mcfnord commentedon Aug 14, 2026
🤖 AI: The
sound.cpphunk from ann0see/jamulus#286 has not reachedmain. That PR closed on 2026-08-08 with "I HOPE that everything from this PR is now captured upstream (issue #3868)"; theclient.cppparts did land via PR #3851, the ASIO one did not.At
5146a072,ASIOExit()occurs once in the ASIO backend, insideUnloadCurrentDriver(). The capability-failure branch still ends in a bareremoveCurrentDriver(), so the danglingtheAsioDriverthis issue describes, measured on real hardware, is still reachable on currentmain. A search of this repository returns no pull request mentioningASIOExit, open or closed.Is that hunk still intended for merge?
ann0see commentedon Aug 14, 2026
I'd like to not look at this ATM since we've fixed the hang (which is the most important one).
Feel free to take it over after the PR freeze.