Memory leak found by Coverity:
CID
1412251 (#2 of 2): Resource leak (RESOURCE_LEAK)
21. leaked_storage: Variable head going out of scope leaks the storage it points to.
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
struct lttng_id_tracker_rcu *p = lf->p;
uint32_t hash = hash_32(id, 32);
bool allocated = false;
+ int ret;
if (!p) {
p = lttng_id_tracker_rcu_create();
}
head = &p->id_hash[hash & (LTTNG_ID_TABLE_SIZE - 1)];
lttng_hlist_for_each_entry(e, head, hlist) {
- if (id == e->id)
- return -EEXIST;
+ if (id == e->id) {
+ ret = -EEXIST;
+ goto error;
+ }
}
e = kmalloc(sizeof(struct lttng_id_hash_node), GFP_KERNEL);
- if (!e)
- return -ENOMEM;
+ if (!e) {
+ ret = -ENOMEM;
+ goto error;
+ }
e->id = id;
hlist_add_head_rcu(&e->hlist, head);
if (allocated) {
rcu_assign_pointer(lf->p, p);
}
return 0;
+
+error:
+ if (allocated) {
+ kfree(p);
+ }
+ return ret;
}
static