]> git.karo-electronics.de Git - karo-tx-linux.git/commit
ALSA: usb-audio: Fix memory leak and corruption in mixer_us16x08.c
authorTakashi Iwai <tiwai@suse.de>
Wed, 22 Feb 2017 07:00:25 +0000 (08:00 +0100)
committerTakashi Iwai <tiwai@suse.de>
Wed, 22 Feb 2017 13:24:09 +0000 (14:24 +0100)
commite2810d76c5f3b0152fa0f7c40170e123b33e058c
tree4842d37a6231ced8c5bf33a87561adbf21282f7e
parent89b593c30e83ee19b7e7c6c7d6092669bebf343e
ALSA: usb-audio: Fix memory leak and corruption in mixer_us16x08.c

There are a few places leaking memory and doing double-free in
mixer_us16x08.c.

The driver allocates a usb_mixer_elem_info object at each
add_new_ctl() call.  This has to be freed via kctl->private_free, but
currently this is done properly only for some controls.

Also, the driver allocates three external objects (comp_store,
eq_store, meter_store), and these are referred in elem->private_data
(it's not kctl->private_data).  And these have to be released, but
there are none doing it.  Moreover, these extra objects have to be
released only once.  Thus the release should be done only by the first
kctl element that refers to it.

For fixing these, we call either snd_usb_mixer_elem_free() (only for
kctl->private_data) or elem_private_free() (for both
kctl->private_data and elem->private_data) via kctl->private_free
appropriately.

Last but not least, snd_us16x08_controls_create() may return in the
middle without releasing the allocated *_store objects due to an
error.  For fixing this, we shuffle the allocation code so that it's
called just before its reference.

Fixes: d2bb390a2081 ("ALSA: usb-audio: Tascam US-16x08 DSP mixer quirk")
Reported-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/usb/mixer_us16x08.c
sound/usb/mixer_us16x08.h