public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* fix usbmixer double kfree.
@ 2006-03-06  8:49 Dave Jones
  2006-03-06 13:43 ` Takashi Iwai
  2006-03-07  0:41 ` Andrew Morton
  0 siblings, 2 replies; 4+ messages in thread
From: Dave Jones @ 2006-03-06  8:49 UTC (permalink / raw)
  To: Linux Kernel; +Cc: tiwai

snd_ctl_add() kfree's the kcontrol already if we fail there,
so this driver is currently doing a double kfree.

Coverity bug #959

Signed-off-by: Dave Jones <davej@redhat.com>

--- linux-2.6/sound/usb/usbmixer.c~	2006-03-06 03:40:20.000000000 -0500
+++ linux-2.6/sound/usb/usbmixer.c	2006-03-06 03:45:03.000000000 -0500
@@ -434,7 +434,6 @@ static int add_control_to_empty(struct m
 		kctl->id.index++;
 	if ((err = snd_ctl_add(state->chip->card, kctl)) < 0) {
 		snd_printd(KERN_ERR "cannot add control (err = %d)\n", err);
-		snd_ctl_free_one(kctl);
 		return err;
 	}
 	cval->elem_id = &kctl->id;

-- 
http://www.codemonkey.org.uk

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: fix usbmixer double kfree.
  2006-03-06  8:49 fix usbmixer double kfree Dave Jones
@ 2006-03-06 13:43 ` Takashi Iwai
  2006-03-07  0:41 ` Andrew Morton
  1 sibling, 0 replies; 4+ messages in thread
From: Takashi Iwai @ 2006-03-06 13:43 UTC (permalink / raw)
  To: Dave Jones; +Cc: Linux Kernel

At Mon, 6 Mar 2006 03:49:51 -0500,
Dave Jones wrote:
> 
> snd_ctl_add() kfree's the kcontrol already if we fail there,
> so this driver is currently doing a double kfree.
> 
> Coverity bug #959
> 
> Signed-off-by: Dave Jones <davej@redhat.com>
>
> --- linux-2.6/sound/usb/usbmixer.c~	2006-03-06 03:40:20.000000000 -0500
> +++ linux-2.6/sound/usb/usbmixer.c	2006-03-06 03:45:03.000000000 -0500
> @@ -434,7 +434,6 @@ static int add_control_to_empty(struct m
>  		kctl->id.index++;
>  	if ((err = snd_ctl_add(state->chip->card, kctl)) < 0) {
>  		snd_printd(KERN_ERR "cannot add control (err = %d)\n", err);
> -		snd_ctl_free_one(kctl);
>  		return err;
>  	}
>  	cval->elem_id = &kctl->id;
> 


Thanks, applied to ALSA tree now, too.

Signed-off-by: Takashi Iwai <tiwai@suse.de>


Takashi

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: fix usbmixer double kfree.
  2006-03-06  8:49 fix usbmixer double kfree Dave Jones
  2006-03-06 13:43 ` Takashi Iwai
@ 2006-03-07  0:41 ` Andrew Morton
  2006-03-07 11:13   ` Takashi Iwai
  1 sibling, 1 reply; 4+ messages in thread
From: Andrew Morton @ 2006-03-07  0:41 UTC (permalink / raw)
  To: Dave Jones; +Cc: linux-kernel, tiwai

Dave Jones <davej@redhat.com> wrote:
>
> snd_ctl_add() kfree's the kcontrol already if we fail there,
> so this driver is currently doing a double kfree.

Well sometimes it does.  If we hit one of those snd_assert() abominations,
snd_ctl_add() will return error without freeing the kcontrol.

Still, a leak is better than a double-free.

> --- linux-2.6/sound/usb/usbmixer.c~	2006-03-06 03:40:20.000000000 -0500
> +++ linux-2.6/sound/usb/usbmixer.c	2006-03-06 03:45:03.000000000 -0500
> @@ -434,7 +434,6 @@ static int add_control_to_empty(struct m
>  		kctl->id.index++;
>  	if ((err = snd_ctl_add(state->chip->card, kctl)) < 0) {
>  		snd_printd(KERN_ERR "cannot add control (err = %d)\n", err);
> -		snd_ctl_free_one(kctl);
>  		return err;
>  	}
>  	cval->elem_id = &kctl->id;


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: fix usbmixer double kfree.
  2006-03-07  0:41 ` Andrew Morton
@ 2006-03-07 11:13   ` Takashi Iwai
  0 siblings, 0 replies; 4+ messages in thread
From: Takashi Iwai @ 2006-03-07 11:13 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Dave Jones, linux-kernel

At Mon, 6 Mar 2006 16:41:11 -0800,
Andrew Morton wrote:
> 
> Dave Jones <davej@redhat.com> wrote:
> >
> > snd_ctl_add() kfree's the kcontrol already if we fail there,
> > so this driver is currently doing a double kfree.
> 
> Well sometimes it does.  If we hit one of those snd_assert() abominations,
> snd_ctl_add() will return error without freeing the kcontrol.

Indeed.  I'll fix them later.

> Still, a leak is better than a double-free.

Yep :)


thanks,

Takashi

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2006-03-07 11:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-03-06  8:49 fix usbmixer double kfree Dave Jones
2006-03-06 13:43 ` Takashi Iwai
2006-03-07  0:41 ` Andrew Morton
2006-03-07 11:13   ` Takashi Iwai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox