From: Yanchuan Nian <ycnian@gmail.com>
To: pablo@netfilter.org
Cc: netfilter-devel@vger.kernel.org, Yanchuan Nian <ycnian@gmail.com>
Subject: [nft PATCH] Fix memory leak in nft get operation
Date: Mon, 11 Aug 2014 10:24:24 +0800 [thread overview]
Message-ID: <1407723864-18211-1-git-send-email-ycnian@gmail.com> (raw)
Some memories are forgotten to release on the error path in get operation.
Just release them. Also, in netlink_get_chain, it's better to return
immediately when a error is detected.
Signed-off-by: Yanchuan Nian <ycnian@gmail.com>
---
src/netlink.c | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/src/netlink.c b/src/netlink.c
index e149215..dc7a7c4 100644
--- a/src/netlink.c
+++ b/src/netlink.c
@@ -751,15 +751,17 @@ int netlink_get_chain(struct netlink_ctx *ctx, const struct handle *h,
nlc = alloc_nft_chain(h);
err = mnl_nft_chain_get(nf_sock, nlc, 0);
+ if (err < 0) {
+ nft_chain_free(nlc);
+ return netlink_io_error(ctx, loc,
+ "Could not receive chain from kernel: %s",
+ strerror(errno));
+ }
chain = netlink_delinearize_chain(ctx, nlc);
list_add_tail(&chain->list, &ctx->list);
nft_chain_free(nlc);
- if (err < 0)
- return netlink_io_error(ctx, loc,
- "Could not receive chain from kernel: %s",
- strerror(errno));
return err;
}
@@ -1218,16 +1220,18 @@ int netlink_get_set(struct netlink_ctx *ctx, const struct handle *h,
nls = alloc_nft_set(h);
netlink_dump_set(nls);
err = mnl_nft_set_get(nf_sock, nls);
- if (err < 0)
+ if (err < 0) {
+ nft_set_free(nls);
return netlink_io_error(ctx, loc,
"Could not receive set from kernel: %s",
strerror(errno));
+ }
set = netlink_delinearize_set(ctx, nls);
+ nft_set_free(nls);
if (set == NULL)
return -1;
list_add_tail(&set->list, &ctx->list);
- nft_set_free(nls);
return err;
}
@@ -1415,6 +1419,7 @@ int netlink_get_setelems(struct netlink_ctx *ctx, const struct handle *h,
err = mnl_nft_setelem_get(nf_sock, nls);
if (err < 0) {
+ nft_set_free(nls);
if (errno == EINTR)
return -1;
--
1.9.3
reply other threads:[~2014-08-11 2:21 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=1407723864-18211-1-git-send-email-ycnian@gmail.com \
--to=ycnian@gmail.com \
--cc=netfilter-devel@vger.kernel.org \
--cc=pablo@netfilter.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).