[alsa-devel] [PATCH 4/5] ALSA: usb-audio: deallocate memory objects in error path
Takashi Iwai
tiwai at suse.de
Mon Feb 20 21:49:19 CET 2017
On Mon, 20 Feb 2017 21:09:20 +0100,
Takashi Sakamoto wrote:
>
> Some functions for quirks of Tascam US-16x08 have memory leaks.
>
> This commit fixes the bugs.
>
> Fixes: d2bb390a2081 ("ALSA: usb-audio: Tascam US-16x08 DSP mixer quirk")
> Signed-off-by: Takashi Sakamoto <o-takashi at sakamocchi.jp>
> ---
> sound/usb/mixer_us16x08.c | 27 ++++++++++++++++-----------
> 1 file changed, 16 insertions(+), 11 deletions(-)
>
> diff --git a/sound/usb/mixer_us16x08.c b/sound/usb/mixer_us16x08.c
> index 5dae63c..d34dd1c 100644
> --- a/sound/usb/mixer_us16x08.c
> +++ b/sound/usb/mixer_us16x08.c
> @@ -1082,8 +1082,8 @@ static int add_new_ctl(struct usb_mixer_interface *mixer,
>
> kctl = snd_ctl_new1(ncontrol, elem);
> if (!kctl) {
> - kfree(elem);
> - return -ENOMEM;
> + err = -ENOMEM;
> + goto end;
> }
>
> kctl->private_free = freeer;
> @@ -1092,11 +1092,12 @@ static int add_new_ctl(struct usb_mixer_interface *mixer,
>
> err = snd_usb_mixer_add_control(&elem->head, kctl);
> if (err < 0)
> - return err;
> + goto end;
>
> if (elem_ret)
> *elem_ret = elem;
> -
> +end:
> + kfree(elem);
> return 0;
This will release elem even for the success case, no?
Takashi
More information about the Alsa-devel
mailing list