Commit 53f9d273 authored by Simon Ruderich's avatar Simon Ruderich
Browse files

slsm: tree: slsm_insert_helper: fix memory leak in error path

parent c7f2d339
......@@ -307,7 +307,7 @@ out:
/**
* @t: root of the tree in which the rule should be inserted
* @path: where the rule is to be inserted, takes ownership
* @rule: the rule, will be copied
* @rule: the rule, will be copied, takes ownership of references (e.g. app)
*
* Returns: 0 or error value
*/
......@@ -316,8 +316,11 @@ static int slsm_insert_helper(struct tree_node *t, char *path,
char *component, *next = path + 1; /* skip leading slash */
struct tree_node *t_next = t;
if (!*path || *path != '/')
if (!*path || *path != '/') {
kfree(path);
kfree(rule->app);
return -EINVAL;
}
if (!*next) {
/* / is target node, we're already there */
......@@ -350,7 +353,7 @@ static int slsm_insert_helper(struct tree_node *t, char *path,
GFP_KERNEL);
if (!more_children) {
kfree(path); /* no reference stored so far */
return -ENOMEM;
goto enomem;
}
t->children = more_children;
......@@ -371,7 +374,7 @@ static int slsm_insert_helper(struct tree_node *t, char *path,
if (!t->children)
/* what we alloced so far is already referenced and
* consistent, leave it in place */
return -ENOMEM;
goto enomem;
t->children[t->children_used] =
(struct tree_node){ .name = component };
......@@ -392,7 +395,7 @@ insert_rule:
new_capacity * sizeof(*more_rules),
GFP_KERNEL);
if (!more_rules)
return -ENOMEM;
goto enomem;
t->rules = more_rules;
t->rules_capacity = new_capacity;
......@@ -402,6 +405,10 @@ insert_rule:
t->rules_used++;
return 0;
enomem:
kfree(rule->app);
return -ENOMEM;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment