From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Subject: [PATCH nft] cache: memleak list of chain
Date: Tue, 2 Mar 2021 12:48:47 +0100 [thread overview]
Message-ID: <20210302114847.3865-2-pablo@netfilter.org> (raw)
In-Reply-To: <20210302114847.3865-1-pablo@netfilter.org>
Release chain list from the error path.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
src/rule.c | 39 ++++++++++++++++++++++++++-------------
1 file changed, 26 insertions(+), 13 deletions(-)
diff --git a/src/rule.c b/src/rule.c
index 367c5c8be952..cf4d2cbef27b 100644
--- a/src/rule.c
+++ b/src/rule.c
@@ -170,32 +170,42 @@ static int cache_init_objects(struct netlink_ctx *ctx, unsigned int flags)
if (flags & NFT_CACHE_SET_BIT) {
ret = netlink_list_sets(ctx, &table->handle);
list_splice_tail_init(&ctx->list, &table->sets);
- if (ret < 0)
- return -1;
+ if (ret < 0) {
+ ret = -1;
+ goto cache_fails;
+ }
}
if (flags & NFT_CACHE_SETELEM_BIT) {
list_for_each_entry(set, &table->sets, list) {
ret = netlink_list_setelems(ctx, &set->handle,
set);
- if (ret < 0)
- return -1;
+ if (ret < 0) {
+ ret = -1;
+ goto cache_fails;
+ }
}
}
if (flags & NFT_CACHE_CHAIN_BIT) {
ret = chain_cache_init(ctx, table, chain_list);
- if (ret < 0)
- return -1;
+ if (ret < 0) {
+ ret = -1;
+ goto cache_fails;
+ }
}
if (flags & NFT_CACHE_FLOWTABLE_BIT) {
ret = netlink_list_flowtables(ctx, &table->handle);
- if (ret < 0)
- return -1;
+ if (ret < 0) {
+ ret = -1;
+ goto cache_fails;
+ }
list_splice_tail_init(&ctx->list, &table->flowtables);
}
if (flags & NFT_CACHE_OBJECT_BIT) {
ret = netlink_list_objs(ctx, &table->handle);
- if (ret < 0)
- return -1;
+ if (ret < 0) {
+ ret = -1;
+ goto cache_fails;
+ }
list_splice_tail_init(&ctx->list, &table->objs);
}
@@ -208,15 +218,18 @@ static int cache_init_objects(struct netlink_ctx *ctx, unsigned int flags)
rule->handle.chain.name);
list_move_tail(&rule->list, &chain->rules);
}
- if (ret < 0)
- return -1;
+ if (ret < 0) {
+ ret = -1;
+ goto cache_fails;
+ }
}
}
+cache_fails:
if (flags & NFT_CACHE_CHAIN_BIT)
nftnl_chain_list_free(chain_list);
- return 0;
+ return ret;
}
static int cache_init(struct netlink_ctx *ctx, unsigned int flags)
--
2.20.1
prev parent reply other threads:[~2021-03-02 23:38 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-02 11:48 [PATCH nft] mnl: remove nft_mnl_socket_reopen() Pablo Neira Ayuso
2021-03-02 11:48 ` Pablo Neira Ayuso [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210302114847.3865-2-pablo@netfilter.org \
--to=pablo@netfilter.org \
--cc=netfilter-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).