[ALSA] Fix memory leaks in error path of control.c
Modules: Control Midlevel Fix memory leaks in error path of control.c (only with CONFIG_SND_DEBUG=y). Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
parent
c5c079e31c
commit
c6077b3000
@ -309,28 +309,29 @@ int snd_ctl_add(struct snd_card *card, struct snd_kcontrol *kcontrol)
|
|||||||
{
|
{
|
||||||
struct snd_ctl_elem_id id;
|
struct snd_ctl_elem_id id;
|
||||||
unsigned int idx;
|
unsigned int idx;
|
||||||
|
int err = -EINVAL;
|
||||||
|
|
||||||
snd_assert(card != NULL, return -EINVAL);
|
|
||||||
if (! kcontrol)
|
if (! kcontrol)
|
||||||
return -EINVAL;
|
return err;
|
||||||
snd_assert(kcontrol->info != NULL, return -EINVAL);
|
snd_assert(card != NULL, goto error);
|
||||||
|
snd_assert(kcontrol->info != NULL, goto error);
|
||||||
id = kcontrol->id;
|
id = kcontrol->id;
|
||||||
down_write(&card->controls_rwsem);
|
down_write(&card->controls_rwsem);
|
||||||
if (snd_ctl_find_id(card, &id)) {
|
if (snd_ctl_find_id(card, &id)) {
|
||||||
up_write(&card->controls_rwsem);
|
up_write(&card->controls_rwsem);
|
||||||
snd_ctl_free_one(kcontrol);
|
|
||||||
snd_printd(KERN_ERR "control %i:%i:%i:%s:%i is already present\n",
|
snd_printd(KERN_ERR "control %i:%i:%i:%s:%i is already present\n",
|
||||||
id.iface,
|
id.iface,
|
||||||
id.device,
|
id.device,
|
||||||
id.subdevice,
|
id.subdevice,
|
||||||
id.name,
|
id.name,
|
||||||
id.index);
|
id.index);
|
||||||
return -EBUSY;
|
err = -EBUSY;
|
||||||
|
goto error;
|
||||||
}
|
}
|
||||||
if (snd_ctl_find_hole(card, kcontrol->count) < 0) {
|
if (snd_ctl_find_hole(card, kcontrol->count) < 0) {
|
||||||
up_write(&card->controls_rwsem);
|
up_write(&card->controls_rwsem);
|
||||||
snd_ctl_free_one(kcontrol);
|
err = -ENOMEM;
|
||||||
return -ENOMEM;
|
goto error;
|
||||||
}
|
}
|
||||||
list_add_tail(&kcontrol->list, &card->controls);
|
list_add_tail(&kcontrol->list, &card->controls);
|
||||||
card->controls_count += kcontrol->count;
|
card->controls_count += kcontrol->count;
|
||||||
@ -340,6 +341,10 @@ int snd_ctl_add(struct snd_card *card, struct snd_kcontrol *kcontrol)
|
|||||||
for (idx = 0; idx < kcontrol->count; idx++, id.index++, id.numid++)
|
for (idx = 0; idx < kcontrol->count; idx++, id.index++, id.numid++)
|
||||||
snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_ADD, &id);
|
snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_ADD, &id);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
error:
|
||||||
|
snd_ctl_free_one(kcontrol);
|
||||||
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user