1 From cb5173594d50c72b7bfa14113dfc5084b4d2f726 Mon Sep 17 00:00:00 2001
2 From: Wenwen Wang <wang6495@umn.edu>
3 Date: Sat, 27 Apr 2019 01:06:46 -0500
4 Subject: ALSA: usb-audio: Fix a memory leak bug
6 From: Wenwen Wang <wang6495@umn.edu>
8 commit cb5173594d50c72b7bfa14113dfc5084b4d2f726 upstream.
10 In parse_audio_selector_unit(), the string array 'namelist' is allocated
11 through kmalloc_array(), and each string pointer in this array, i.e.,
12 'namelist[]', is allocated through kmalloc() in the following for loop.
13 Then, a control instance 'kctl' is created by invoking snd_ctl_new1(). If
14 an error occurs during the creation process, the string array 'namelist',
15 including all string pointers in the array 'namelist[]', should be freed,
16 before the error code ENOMEM is returned. However, the current code does
17 not free 'namelist[]', resulting in memory leaks.
19 To fix the above issue, free all string pointers 'namelist[]' in a loop.
21 Signed-off-by: Wenwen Wang <wang6495@umn.edu>
22 Cc: <stable@vger.kernel.org>
23 Signed-off-by: Takashi Iwai <tiwai@suse.de>
24 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
27 sound/usb/mixer.c | 2 ++
28 1 file changed, 2 insertions(+)
30 --- a/sound/usb/mixer.c
31 +++ b/sound/usb/mixer.c
32 @@ -2112,6 +2112,8 @@ static int parse_audio_selector_unit(str
33 kctl = snd_ctl_new1(&mixer_selectunit_ctl, cval);
35 usb_audio_err(state->chip, "cannot malloc kcontrol\n");
36 + for (i = 0; i < desc->bNrInPins; i++)