Skip to content
Snippets Groups Projects
Commit 868b82a2 authored by David Herrmann's avatar David Herrmann
Browse files

match: make match_owner_ref_rule() consistent


Right now, this function only takes a reference if it created a new
match rule, or if it returned one. This is quite inconsistent with its
function name, and hard to follow. Furthermore, there is no reason to
do so.

There are two options:

 * Always take a reference, just as the name suggests.

 * Only take a reference when returning a pointer.

The second option would make the function a no-op, whenever a new match
is created. Hence, we opt for the first version.

Any other behavior is odd and hard to understand by any reader. If that
behavior is really needed, we should provide something else.

Note that the only user of match_onwer_ref_rule() without an output
argument is BecomeMonitor(). However, this function is completely fine
with incrementing the ref-count for each entry it adds. There is no
reliance on the previous behavior.

Signed-off-by: default avatarDavid Herrmann <dh.herrmann@gmail.com>
parent 194781d9
No related branches found
No related tags found
No related merge requests found
......@@ -506,8 +506,8 @@ void match_owner_deinit(MatchOwner *owner) {
* match_owner_ref_rule() - XXX
*/
int match_owner_ref_rule(MatchOwner *owner, MatchRule **rulep, User *user, const char *rule_string) {
_c_cleanup_(match_rule_user_unrefp) MatchRule *rule = NULL;
CRBNode **slot, *parent;
MatchRule *rule;
int r;
r = match_rule_new(&rule, owner, user, rule_string);
......@@ -519,16 +519,15 @@ int match_owner_ref_rule(MatchOwner *owner, MatchRule **rulep, User *user, const
slot = c_rbtree_find_slot(&owner->rule_tree, match_rule_compare, &rule->keys, &parent);
if (!slot) {
/* one already exists, take a ref on that instead and drop the one we created */
if (rulep)
*rulep = match_rule_user_ref(c_container_of(parent, MatchRule, owner_node));
match_rule_user_unref(rule);
rule = match_rule_user_ref(c_container_of(parent, MatchRule, owner_node));
} else {
/* link the new rule into the rbtree */
c_rbtree_add(&owner->rule_tree, parent, slot, &rule->owner_node);
if (rulep)
*rulep = rule;
rule = NULL;
}
if (rulep)
*rulep = rule;
return 0;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment