[PATCH 9/9] [UBUNTU:sound/core] Fix memory leaks in error path of sound/core/control.c

crimsun at fungus.sh.nu crimsun at fungus.sh.nu
Tue Mar 28 08:20:06 UTC 2006


Subject: [PATCH 9/9] [UBUNTU:sound/core] Fix memory leaks in error path of sound/core/control.c

UpstreamStatus: Applied, backported from http://kernel.org/git/?p=linux/kernel/git/perex/alsa-current.git;a=commitdiff;h=c6077b3000184c7f69c4798b9025e5fbd69c8c62

This patch from Takashi Iwai fixes memory leaks in the error path of
the control midlevel. While they're only applicable if
CONFIG_SND_DEBUG=y (and it's not in our kernel), it's still better to
plug the leaks.

Signed-off-by: Daniel T Chen <crimsun at ubuntu.com>

---

 sound/core/control.c |   19 +++++++++++++------
 1 files changed, 13 insertions(+), 6 deletions(-)

077a4734648e245a2bd3455496979a626bb27949
diff --git a/sound/core/control.c b/sound/core/control.c
index 212c46a..2a1d627 100644
--- a/sound/core/control.c
+++ b/sound/core/control.c
@@ -308,26 +308,29 @@ int snd_ctl_add(snd_card_t * card, snd_k
 {
 	snd_ctl_elem_id_t id;
 	unsigned int idx;
+	int err = -EINVAL;
 
-	snd_assert(card != NULL && kcontrol != NULL, return -EINVAL);
-	snd_assert(kcontrol->info != NULL, return -EINVAL);
+	if (! kcontrol)
+		return err;
+	snd_assert(card != NULL, goto error);
+	snd_assert(kcontrol->info != NULL, goto error);
 	id = kcontrol->id;
 	down_write(&card->controls_rwsem);
 	if (snd_ctl_find_id(card, &id)) {
 		up_write(&card->controls_rwsem);
-		snd_ctl_free_one(kcontrol);
 		snd_printd(KERN_ERR "control %i:%i:%i:%s:%i is already present\n",
 					id.iface,
 					id.device,
 					id.subdevice,
 					id.name,
 					id.index);
-		return -EBUSY;
+		err = -EBUSY;
+		goto error;
 	}
 	if (snd_ctl_find_hole(card, kcontrol->count) < 0) {
 		up_write(&card->controls_rwsem);
-		snd_ctl_free_one(kcontrol);
-		return -ENOMEM;
+		err = -ENOMEM;
+		goto error;
 	}
 	list_add_tail(&kcontrol->list, &card->controls);
 	card->controls_count += kcontrol->count;
@@ -337,6 +340,10 @@ int snd_ctl_add(snd_card_t * card, snd_k
 	for (idx = 0; idx < kcontrol->count; idx++, id.index++, id.numid++)
 		snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_ADD, &id);
 	return 0;
+
+error:
+	snd_ctl_free_one(kcontrol);
+	return err;
 }
 
 /**
-- 
1.1.3


-- 
Daniel T. Chen            crimsun at ubuntu.com
GPG key:   www.sh.nu/~crimsun/pubkey.gpg.asc
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <https://lists.ubuntu.com/archives/kernel-team/attachments/20060328/2085d93c/attachment.sig>


More information about the kernel-team mailing list