From: Wenwen Wang <wang6495@umn.edu>
To: Wenwen Wang <wang6495@umn.edu>
Cc: Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
Jorge Sanjuan <jorge.sanjuan@codethink.co.uk>,
Ruslan Bilovol <ruslan.bilovol@gmail.com>,
"moderated list:SOUND" <alsa-devel@alsa-project.org>,
open list <linux-kernel@vger.kernel.org>
Subject: [PATCH] ALSA: usb-audio: Fix a memory leak bug
Date: Sat, 27 Apr 2019 01:06:46 -0500 [thread overview]
Message-ID: <1556345208-1210-1-git-send-email-wang6495@umn.edu> (raw)
In parse_audio_selector_unit(), the string array 'namelist' is allocated
through kmalloc_array(), and each string pointer in this array, i.e.,
'namelist[]', is allocated through kmalloc() in the following for loop.
Then, a control instance 'kctl' is created by invoking snd_ctl_new1(). If
an error occurs during the creation process, the string array 'namelist',
including all string pointers in the array 'namelist[]', should be freed,
before the error code ENOMEM is returned. However, the current code does
not free 'namelist[]', resulting in memory leaks.
To fix the above issue, free all string pointers 'namelist[]' in a loop.
Signed-off-by: Wenwen Wang <wang6495@umn.edu>
---
sound/usb/mixer.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/sound/usb/mixer.c b/sound/usb/mixer.c
index 73d7dff..53dccbf 100644
--- a/sound/usb/mixer.c
+++ b/sound/usb/mixer.c
@@ -2675,6 +2675,8 @@ static int parse_audio_selector_unit(struct mixer_build *state, int unitid,
kctl = snd_ctl_new1(&mixer_selectunit_ctl, cval);
if (! kctl) {
usb_audio_err(state->chip, "cannot malloc kcontrol\n");
+ for (i = 0; i < desc->bNrInPins; i++)
+ kfree(namelist[i]);
kfree(namelist);
kfree(cval);
return -ENOMEM;
--
2.7.4
next reply other threads:[~2019-04-27 6:06 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-27 6:06 Wenwen Wang [this message]
2019-04-28 7:12 ` [PATCH] ALSA: usb-audio: Fix a memory leak bug Takashi Iwai
-- strict thread matches above, loose matches on Subject: below --
2019-08-06 6:13 [PATCH] ALSA: usb-audio: fix " Wenwen Wang
2019-08-06 6:40 ` Takashi Iwai
2019-08-06 7:00 Wenwen Wang
2019-08-06 10:47 ` Takashi Iwai
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=1556345208-1210-1-git-send-email-wang6495@umn.edu \
--to=wang6495@umn.edu \
--cc=alsa-devel@alsa-project.org \
--cc=jorge.sanjuan@codethink.co.uk \
--cc=linux-kernel@vger.kernel.org \
--cc=perex@perex.cz \
--cc=ruslan.bilovol@gmail.com \
--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).