netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Florian Westphal <fw@strlen.de>
To: netfilter-devel@vger.kernel.org
Cc: Florian Westphal <fw@strlen.de>
Subject: [PATCH lnf-ct] src: callback: fix memory leak when ct has dynamically allocated attr
Date: Wed,  3 Jul 2013 12:52:41 +0200	[thread overview]
Message-ID: <1372848761-14444-1-git-send-email-fw@strlen.de> (raw)

Must free ct and exp using the _destroy functions, else we leak attributes with malloc'd data.

Signed-off-by: Florian Westphal <fw@strlen.de>
---
 src/callback.c |   34 ++++++++--------------------------
 1 files changed, 8 insertions(+), 26 deletions(-)

diff --git a/src/callback.c b/src/callback.c
index 684d3b2..19cc663 100644
--- a/src/callback.c
+++ b/src/callback.c
@@ -82,31 +82,13 @@ int __callback(struct nlmsghdr *nlh, struct nfattr *nfa[], void *data)
 		break;
 	}
 
-	switch(ret) {
-	case NFCT_CB_FAILURE:
-		if (ct)
-			free(ct);
-		if (exp)
-			free(exp);
-		ret = NFNL_CB_FAILURE;
-		break;
-	case NFCT_CB_STOP:
-		if (ct)
-			free(ct);
-		if (exp)
-			free(exp);
-		ret = NFNL_CB_STOP;
-		break;
-	case NFCT_CB_CONTINUE:
-		if (ct)
-			free(ct);
-		if (exp)
-			free(exp);
-		ret = NFNL_CB_CONTINUE;
-		break;
-	case NFCT_CB_STOLEN:
-		ret = NFNL_CB_CONTINUE;
-		break;
-	}
+	if (ret == NFCT_CB_STOLEN)
+		return NFNL_CB_CONTINUE;
+
+	if (ct)
+		nfct_destroy(ct);
+	if (exp)
+		nfexp_destroy(exp);
+
 	return ret;
 }
-- 
1.7.8.6


             reply	other threads:[~2013-07-03 10:50 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-03 10:52 Florian Westphal [this message]
2013-07-03 10:55 ` [PATCH lnf-ct] src: callback: fix memory leak when ct has dynamically allocated attr Pablo Neira Ayuso

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=1372848761-14444-1-git-send-email-fw@strlen.de \
    --to=fw@strlen.de \
    --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).