Commit 2d98dde9 authored by Wenwen Wang's avatar Wenwen Wang Committed by Kleber Sacilotto de Souza

ALSA: usb-audio: Fix a memory leak bug

BugLink: https://bugs.launchpad.net/bugs/1832661

commit cb517359 upstream.

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: default avatarWenwen Wang <wang6495@umn.edu>
Cc: <stable@vger.kernel.org>
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarKhalid Elmously <khalid.elmously@canonical.com>
Signed-off-by: default avatarKleber Sacilotto de Souza <kleber.souza@canonical.com>
parent bd968ad0
...@@ -2112,6 +2112,8 @@ static int parse_audio_selector_unit(struct mixer_build *state, int unitid, ...@@ -2112,6 +2112,8 @@ static int parse_audio_selector_unit(struct mixer_build *state, int unitid,
kctl = snd_ctl_new1(&mixer_selectunit_ctl, cval); kctl = snd_ctl_new1(&mixer_selectunit_ctl, cval);
if (! kctl) { if (! kctl) {
usb_audio_err(state->chip, "cannot malloc kcontrol\n"); usb_audio_err(state->chip, "cannot malloc kcontrol\n");
for (i = 0; i < desc->bNrInPins; i++)
kfree(namelist[i]);
kfree(namelist); kfree(namelist);
kfree(cval); kfree(cval);
return -ENOMEM; return -ENOMEM;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment