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>