]> git.alsa-project.org Git - alsa-lib.git/commit
pcm: multi: allow sparse binding maps and fix error-path leak
authorJaroslav Kysela <perex@perex.cz>
Mon, 30 Nov 2026 13:29:36 +0000 (14:29 +0100)
committerJaroslav Kysela <perex@perex.cz>
Mon, 30 Nov 2026 13:30:04 +0000 (14:30 +0100)
commitedffc5f7d5ac4a58896014ab430491ff2b080849
tree6aede2e6c985086178d96db823126334ef477875
parenta60fd22fa19acd476ae465cfb52b5475b8395f93
pcm: multi: allow sparse binding maps and fix error-path leak

Commit 81c4a89eb445 replaced the binding asserts in snd_pcm_multi_open()
with -EINVAL checks, but it rejected sidxs[i] < 0. Sparse binding maps
legitimately leave sidxs[i] == -1 for gap (unmapped) channels:
_snd_pcm_multi_open() initializes channels_sidx[] to -1 and fills in only
the channels that have a bindings entry. Rejecting negative indices broke
valid configurations, and the trailing "if (sidxs[i] < 0) continue;"
became unreachable dead code.

Handle the unmapped case first by storing the slave_idx < 0 sentinel
(which the rest of the plugin already treats as "not bound") and skipping
the channel. The bounds checks then run only for sidxs[i] >= 0, so the
out-of-range read schannels_count[-1] can no longer happen.

The early "return -EINVAL" also leaked multi, multi->slaves and
multi->channels. Route the binding errors through the existing cleanup
block via goto so all allocations are freed.

Fixes: 81c4a89eb445 ("pcm: replace multi plugin binding asserts with -EINVAL checks")
Closes: https://github.com/alsa-project/alsa-lib/issues/536
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
src/pcm/pcm_multi.c