linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ALSA: usb-audio: fix memory leak on cval
@ 2018-03-27 14:30 Colin King
  2018-03-27 15:45 ` Takashi Iwai
  0 siblings, 1 reply; 2+ messages in thread
From: Colin King @ 2018-03-27 14:30 UTC (permalink / raw)
  To: Jaroslav Kysela, Takashi Iwai, Andrew Chant, alsa-devel
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

With the current exit return path of the ctl_info allocation failure
cval is not being freed resulting in a memory leak. Fix this by kfree'ing
it on the return.

Detected by CoverityScan, CID#1466878 ("Resource Leak")

Fixes: 21e9b3e931f7 ("ALSA: usb-audio: fix uac control query argument")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 sound/usb/mixer.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/sound/usb/mixer.c b/sound/usb/mixer.c
index 04dab6f65535..301ad61ed426 100644
--- a/sound/usb/mixer.c
+++ b/sound/usb/mixer.c
@@ -1365,8 +1365,10 @@ static void build_feature_ctl(struct mixer_build *state, void *raw_desc,
 	cval->cmask = ctl_mask;
 
 	ctl_info = get_feature_control_info(control);
-	if (!ctl_info)
+	if (!ctl_info) {
+		kfree(cval);
 		return;
+	}
 	if (state->mixer->protocol == UAC_VERSION_1)
 		cval->val_type = ctl_info->type;
 	else /* UAC_VERSION_2 */
-- 
2.15.1

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

* Re: [PATCH] ALSA: usb-audio: fix memory leak on cval
  2018-03-27 14:30 [PATCH] ALSA: usb-audio: fix memory leak on cval Colin King
@ 2018-03-27 15:45 ` Takashi Iwai
  0 siblings, 0 replies; 2+ messages in thread
From: Takashi Iwai @ 2018-03-27 15:45 UTC (permalink / raw)
  To: Colin King
  Cc: alsa-devel, Andrew Chant, Jaroslav Kysela, kernel-janitors, linux-kernel

On Tue, 27 Mar 2018 16:30:01 +0200,
Colin King wrote:
> 
> From: Colin Ian King <colin.king@canonical.com>
> 
> With the current exit return path of the ctl_info allocation failure
> cval is not being freed resulting in a memory leak. Fix this by kfree'ing
> it on the return.
> 
> Detected by CoverityScan, CID#1466878 ("Resource Leak")
> 
> Fixes: 21e9b3e931f7 ("ALSA: usb-audio: fix uac control query argument")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>

Thanks, applied now.


Takashi

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

end of thread, other threads:[~2018-03-27 15:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-27 14:30 [PATCH] ALSA: usb-audio: fix memory leak on cval Colin King
2018-03-27 15:45 ` Takashi Iwai

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).