2019-08-06 07:01:56

by Wenwen Wang

[permalink] [raw]
Subject: [PATCH] ALSA: usb-audio: fix a memory leak bug

In snd_usb_get_audioformat_uac3(), a structure for channel maps 'chmap' is
allocated through kzalloc() before the execution goto 'found_clock'.
However, this structure is not deallocated if the memory allocation for
'pd' fails, leading to a memory leak bug.

To fix the above issue, free 'fp->chmap' before returning NULL.

Signed-off-by: Wenwen Wang <[email protected]>
---
sound/usb/stream.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/sound/usb/stream.c b/sound/usb/stream.c
index 7ee9d17..e852c7f 100644
--- a/sound/usb/stream.c
+++ b/sound/usb/stream.c
@@ -1043,6 +1043,7 @@ snd_usb_get_audioformat_uac3(struct snd_usb_audio *chip,

pd = kzalloc(sizeof(*pd), GFP_KERNEL);
if (!pd) {
+ kfree(fp->chmap);
kfree(fp->rate_table);
kfree(fp);
return NULL;
--
2.7.4


2019-08-06 10:49:41

by Takashi Iwai

[permalink] [raw]
Subject: Re: [PATCH] ALSA: usb-audio: fix a memory leak bug

On Tue, 06 Aug 2019 09:00:27 +0200,
Wenwen Wang wrote:
>
> In snd_usb_get_audioformat_uac3(), a structure for channel maps 'chmap' is
> allocated through kzalloc() before the execution goto 'found_clock'.
> However, this structure is not deallocated if the memory allocation for
> 'pd' fails, leading to a memory leak bug.
>
> To fix the above issue, free 'fp->chmap' before returning NULL.
>
> Signed-off-by: Wenwen Wang <[email protected]>

Applied, thanks.


Takashi