linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: Dinghao Liu <dinghao.liu@zju.edu.cn>
Cc: kjlu@umn.edu, Jaroslav Kysela <perex@perex.cz>,
	Takashi Iwai <tiwai@suse.com>, "Geoffrey D. Bennett" <g@b4.vu>,
	alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] ALSA: usb-audio: Fix memleak in scarlett2_add_new_ctl
Date: Fri, 07 Aug 2020 10:04:41 +0200	[thread overview]
Message-ID: <s5htuxeanl2.wl-tiwai@suse.de> (raw)
In-Reply-To: <20200807071229.9533-1-dinghao.liu@zju.edu.cn>

On Fri, 07 Aug 2020 09:12:27 +0200,
Dinghao Liu wrote:
> 
> When snd_usb_mixer_add_control() fails, elem needs to be
> freed just like when snd_ctl_new1() fails. However, current
> code is returning directly and ends up leaking memory.

No, this would lead to double-free.  snd_ctl_add() shows a kind of
special behavior, it already releases the object at its error path.


thanks,

Takashi

> 
> Fixes: 9e4d5c1be21f0 ("ALSA: usb-audio: Scarlett Gen 2 mixer interface")
> Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
> ---
>  sound/usb/mixer_scarlett_gen2.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/sound/usb/mixer_scarlett_gen2.c b/sound/usb/mixer_scarlett_gen2.c
> index 74c00c905d24..4b2da0866cdc 100644
> --- a/sound/usb/mixer_scarlett_gen2.c
> +++ b/sound/usb/mixer_scarlett_gen2.c
> @@ -964,8 +964,10 @@ static int scarlett2_add_new_ctl(struct usb_mixer_interface *mixer,
>  	strlcpy(kctl->id.name, name, sizeof(kctl->id.name));
>  
>  	err = snd_usb_mixer_add_control(&elem->head, kctl);
> -	if (err < 0)
> +	if (err < 0) {
> +		kfree(elem);
>  		return err;
> +	}
>  
>  	if (kctl_return)
>  		*kctl_return = kctl;
> -- 
> 2.17.1
> 

  reply	other threads:[~2020-08-07  8:04 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-07  7:12 [PATCH] ALSA: usb-audio: Fix memleak in scarlett2_add_new_ctl Dinghao Liu
2020-08-07  8:04 ` Takashi Iwai [this message]
2020-08-07  9:50   ` dinghao.liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=s5htuxeanl2.wl-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=dinghao.liu@zju.edu.cn \
    --cc=g@b4.vu \
    --cc=kjlu@umn.edu \
    --cc=linux-kernel@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=tiwai@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).