dahdi: Minor fix for alloc/free of 'struct ecfactory'
Do not allocate the structure with GFP_KERNEL under the lock in dahdi_echocan_factory_register and closes a leak in dahdi_echocan_factory_unregister. Signed-off-by: Shaun Ruffell <sruffell@digium.com> Acked-by: Kinsey Moore <kmoore@digium.com> git-svn-id: http://svn.asterisk.org/svn/dahdi/linux/trunk@9590 a0bf4364-ded3-4de4-8d8a-66a801d63aff
This commit is contained in:
@@ -495,28 +495,29 @@ struct ecfactory {
|
||||
int dahdi_register_echocan_factory(const struct dahdi_echocan_factory *ec)
|
||||
{
|
||||
struct ecfactory *cur;
|
||||
struct ecfactory *new;
|
||||
|
||||
WARN_ON(!ec->owner);
|
||||
|
||||
new = kzalloc(sizeof(*new), GFP_KERNEL);
|
||||
if (!new)
|
||||
return -ENOMEM;
|
||||
|
||||
INIT_LIST_HEAD(&new->list);
|
||||
|
||||
spin_lock(&ecfactory_list_lock);
|
||||
|
||||
/* make sure it isn't already registered */
|
||||
list_for_each_entry(cur, &ecfactory_list, list) {
|
||||
if (cur->ec == ec) {
|
||||
spin_unlock(&ecfactory_list_lock);
|
||||
kfree(new);
|
||||
return -EPERM;
|
||||
}
|
||||
}
|
||||
|
||||
if (!(cur = kzalloc(sizeof(*cur), GFP_KERNEL))) {
|
||||
spin_unlock(&ecfactory_list_lock);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
cur->ec = ec;
|
||||
INIT_LIST_HEAD(&cur->list);
|
||||
|
||||
list_add_tail(&cur->list, &ecfactory_list);
|
||||
new->ec = ec;
|
||||
list_add_tail(&new->list, &ecfactory_list);
|
||||
|
||||
spin_unlock(&ecfactory_list_lock);
|
||||
|
||||
@@ -532,6 +533,7 @@ void dahdi_unregister_echocan_factory(const struct dahdi_echocan_factory *ec)
|
||||
list_for_each_entry_safe(cur, next, &ecfactory_list, list) {
|
||||
if (cur->ec == ec) {
|
||||
list_del(&cur->list);
|
||||
kfree(cur);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user