2012-05-18 16:01:09

by Clemens Ladisch

[permalink] [raw]
Subject: Re: kmemleak findings about USB audio recording on 3.3.2

Alexander E. Patrakov wrote:
> On my home computer with linux-3.3.2, kmemleak found a lot of copies of
> this (not only from pulseaudio, but also from wine):
>
> unreferenced object 0xffff88021afaed40 (size 16):
> comm "pulseaudio", pid 839, jiffies 4294711382 (age 31392.844s)
> hex dump (first 16 bytes):
> 80 3e 00 00 c0 5d 00 00 00 7d 00 00 02 00 00 00 .>...]...}......
> backtrace:
> [<ffffffff811620d7>] create_object+0x127/0x2b0
> [<ffffffff81636d81>] kmemleak_alloc+0x21/0x50
> [<ffffffff81157bc3>] __kmalloc+0x103/0x1e0
> [<ffffffffa02f650b>] snd_usb_pcm_open+0x3bb/0x4c0 [snd_usb_audio]

Please try this patch.

--8<---------------------------------------------------------------->8--
ALSA: usb-audio: fix rate_list memory leak

The array of sample rates is reallocated every time when opening
the PCM device, but was freed only once when unplugging the device.

Reported-by: "Alexander E. Patrakov" <[email protected]>
Signed-off-by: Clemens Ladisch <[email protected]>
---
sound/usb/pcm.c | 3 +++
1 files changed, 3 insertions(+), 0 deletions(-)

--- a/sound/usb/pcm.c
+++ b/sound/usb/pcm.c
@@ -783,6 +783,9 @@ static int snd_usb_pcm_check_knot(struct snd_pcm_runtime *runtime,
int count = 0, needs_knot = 0;
int err;

+ kfree(subs->rate_list.list);
+ subs->rate_list.list = NULL;
+
list_for_each_entry(fp, &subs->fmt_list, list) {
if (fp->rates & SNDRV_PCM_RATE_CONTINUOUS)
return 0;


2012-05-27 11:18:40

by Alexander E. Patrakov

[permalink] [raw]
Subject: Re: kmemleak findings about USB audio recording on 3.3.2

2012/5/18 Clemens Ladisch <[email protected]>:
> Please try this patch.
>
> --8<---------------------------------------------------------------->8--
> ALSA: usb-audio: fix rate_list memory leak
>
> The array of sample rates is reallocated every time when opening
> the PCM device, but was freed only once when unplugging the device.
>
> Reported-by: "Alexander E. Patrakov" <[email protected]>
> Signed-off-by: Clemens Ladisch <[email protected]>
> ---
>  sound/usb/pcm.c |    3 +++
>  1 files changed, 3 insertions(+), 0 deletions(-)
>
> --- a/sound/usb/pcm.c
> +++ b/sound/usb/pcm.c
> @@ -783,6 +783,9 @@ static int snd_usb_pcm_check_knot(struct snd_pcm_runtime *runtime,
>        int count = 0, needs_knot = 0;
>        int err;
>
> +       kfree(subs->rate_list.list);
> +       subs->rate_list.list = NULL;
> +
>        list_for_each_entry(fp, &subs->fmt_list, list) {
>                if (fp->rates & SNDRV_PCM_RATE_CONTINUOUS)
>                        return 0;

I have applied this on top of 3.4.0. So far, the microphone works, and
there are no leaks detected.

--
Alexander E. Patrakov

2012-05-31 08:34:28

by Takashi Iwai

[permalink] [raw]
Subject: Re: [alsa-devel] kmemleak findings about USB audio recording on 3.3.2

At Sun, 27 May 2012 17:18:38 +0600,
Alexander E. Patrakov wrote:
>
> 2012/5/18 Clemens Ladisch <[email protected]>:
> > Please try this patch.
> >
> > --8<---------------------------------------------------------------->8--
> > ALSA: usb-audio: fix rate_list memory leak
> >
> > The array of sample rates is reallocated every time when opening
> > the PCM device, but was freed only once when unplugging the device.
> >
> > Reported-by: "Alexander E. Patrakov" <[email protected]>
> > Signed-off-by: Clemens Ladisch <[email protected]>
> > ---
> >  sound/usb/pcm.c |    3 +++
> >  1 files changed, 3 insertions(+), 0 deletions(-)
> >
> > --- a/sound/usb/pcm.c
> > +++ b/sound/usb/pcm.c
> > @@ -783,6 +783,9 @@ static int snd_usb_pcm_check_knot(struct snd_pcm_runtime *runtime,
> >        int count = 0, needs_knot = 0;
> >        int err;
> >
> > +       kfree(subs->rate_list.list);
> > +       subs->rate_list.list = NULL;
> > +
> >        list_for_each_entry(fp, &subs->fmt_list, list) {
> >                if (fp->rates & SNDRV_PCM_RATE_CONTINUOUS)
> >                        return 0;
>
> I have applied this on top of 3.4.0. So far, the microphone works, and
> there are no leaks detected.

OK, I applied the patch to sound git tree now.


thanks,

Takashi