Call kdbus_match_rule_free() in the error path to cleanly free all
associated memory. For this to work, rule->type must be assigned as
soon as possible. Also, make kdbus_match_rule_free() accept NULL
pointers so we don't have to check for that on the call site.
Signed-off-by: Daniel Mack <daniel@zonque.org>
static void kdbus_match_rule_free(struct kdbus_match_rule *rule)
{
+ if (!rule)
+ return;
+
switch (rule->type) {
case KDBUS_ITEM_BLOOM_MASK:
kfree(rule->bloom_mask.data);
break;
}
+ rule->type = item->type;
+
switch (item->type) {
/* First matches for userspace messages */
case KDBUS_ITEM_BLOOM_MASK: {
}
if (ret < 0) {
- kfree(rule);
+ kdbus_match_rule_free(rule);
break;
}
- rule->type = item->type;
-
list_add_tail(&rule->rules_entry, &entry->rules_list);
}