Skip to contentSkip to conversation

fix usbmixer double kfree.

PATCH Applied Dave Jones 3 participants 4 messages Mar 6, 2006 – Mar 7, 2006 Sound

lore
Share & tools
lore

Dave Jones

author
#0 lore raw

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

Coverity bug #959

sound/usb/usbmixer.c renamed from sound/usb/usbmixer.c~ +0 -1
@@ -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;
Signature · 1 line
http://www.codemonkey.org.uk
Applied
#1 lore raw

At Mon, 6 Mar 2006 03:49:51 -0500,

Quoted 12 lines · Dave Jones

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

Coverity bug #959

sound/usb/usbmixer.c static int add_control_to_empty(struct m · line 439

Quoted 7 lines
sound/usb/usbmixer.c renamed from sound/usb/usbmixer.c~ +0 -1
@@ -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.

Takashi

#2 lore raw
In reply to Dave Jones
Quoted 3 lines · Dave Jones

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.

Quoted 10 lines
sound/usb/usbmixer.c renamed from sound/usb/usbmixer.c~ +0 -1
@@ -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;
#3 lore raw

At Mon, 6 Mar 2006 16:41:11 -0800,

Quoted 8 lines · Andrew Morton
Quoted 3 lines · Dave Jones

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.

Quoted 1 line

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

Yep :)

thanks,

Takashi