public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ALSA: usb-audio: Fix memleak in scarlett2_add_new_ctl
@ 2020-08-07  7:12 Dinghao Liu
  2020-08-07  8:04 ` Takashi Iwai
  0 siblings, 1 reply; 3+ messages in thread
From: Dinghao Liu @ 2020-08-07  7:12 UTC (permalink / raw)
  To: dinghao.liu, kjlu
  Cc: Jaroslav Kysela, Takashi Iwai, Geoffrey D. Bennett, alsa-devel,
	linux-kernel

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.

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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-08-07  9:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2020-08-07  9:50   ` dinghao.liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox