diff options
author | Pablo Neira Ayuso <pablo@netfilter.org> | 2015-07-06 14:29:33 +0200 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2015-08-18 01:13:35 +0200 |
commit | 327554218c59902965a160b71c7b6021a0d8bf4b (patch) | |
tree | 5af22ea3f55a3fde432e2e01f983df92728336c2 /src | |
parent | c54fbd53c73fd0426329bfbeaa99bdda244542a9 (diff) |
rule: add chain reference counter
When adding declared chains to the cache, we may hold more than one single
reference from struct cmd and the cache.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/rule.c | 9 |
1 files changed, 9 insertions, 0 deletions
@@ -444,6 +444,7 @@ struct chain *chain_alloc(const char *name) struct chain *chain; chain = xzalloc(sizeof(*chain)); + chain->refcnt = 1; init_list_head(&chain->rules); init_list_head(&chain->scope.symbols); if (name != NULL) @@ -453,10 +454,18 @@ struct chain *chain_alloc(const char *name) return chain; } +struct chain *chain_get(struct chain *chain) +{ + chain->refcnt++; + return chain; +} + void chain_free(struct chain *chain) { struct rule *rule, *next; + if (--chain->refcnt > 0) + return; list_for_each_entry_safe(rule, next, &chain->rules, list) rule_free(rule); handle_free(&chain->handle); |