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: ...@@ -307,7 +307,7 @@ out:
/** /**
* @t: root of the tree in which the rule should be inserted * @t: root of the tree in which the rule should be inserted
* @path: where the rule is to be inserted, takes ownership * @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 * Returns: 0 or error value
*/ */
...@@ -316,8 +316,11 @@ static int slsm_insert_helper(struct tree_node *t, char *path, ...@@ -316,8 +316,11 @@ static int slsm_insert_helper(struct tree_node *t, char *path,
char *component, *next = path + 1; /* skip leading slash */ char *component, *next = path + 1; /* skip leading slash */
struct tree_node *t_next = t; struct tree_node *t_next = t;
if (!*path || *path != '/') if (!*path || *path != '/') {
kfree(path);
kfree(rule->app);
return -EINVAL; return -EINVAL;
}
if (!*next) { if (!*next) {
/* / is target node, we're already there */ /* / is target node, we're already there */
...@@ -350,7 +353,7 @@ static int slsm_insert_helper(struct tree_node *t, char *path, ...@@ -350,7 +353,7 @@ static int slsm_insert_helper(struct tree_node *t, char *path,
GFP_KERNEL); GFP_KERNEL);
if (!more_children) { if (!more_children) {
kfree(path); /* no reference stored so far */ kfree(path); /* no reference stored so far */
return -ENOMEM; goto enomem;
} }
t->children = more_children; t->children = more_children;
...@@ -371,7 +374,7 @@ static int slsm_insert_helper(struct tree_node *t, char *path, ...@@ -371,7 +374,7 @@ static int slsm_insert_helper(struct tree_node *t, char *path,
if (!t->children) if (!t->children)
/* what we alloced so far is already referenced and /* what we alloced so far is already referenced and
* consistent, leave it in place */ * consistent, leave it in place */
return -ENOMEM; goto enomem;
t->children[t->children_used] = t->children[t->children_used] =
(struct tree_node){ .name = component }; (struct tree_node){ .name = component };
...@@ -392,7 +395,7 @@ insert_rule: ...@@ -392,7 +395,7 @@ insert_rule:
new_capacity * sizeof(*more_rules), new_capacity * sizeof(*more_rules),
GFP_KERNEL); GFP_KERNEL);
if (!more_rules) if (!more_rules)
return -ENOMEM; goto enomem;
t->rules = more_rules; t->rules = more_rules;
t->rules_capacity = new_capacity; t->rules_capacity = new_capacity;
...@@ -402,6 +405,10 @@ insert_rule: ...@@ -402,6 +405,10 @@ insert_rule:
t->rules_used++; t->rules_used++;
return 0; 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