Blame SOURCES/0009-evaluate-Fix-memleak-in-stmt_reject_gen_dependency.patch

a05102
From 56d8528fdd3c3f7db138622d94d2a6bac6b46e4e Mon Sep 17 00:00:00 2001
a05102
From: Phil Sutter <psutter@redhat.com>
a05102
Date: Wed, 20 Jun 2018 09:22:47 +0200
a05102
Subject: [PATCH] evaluate: Fix memleak in stmt_reject_gen_dependency()
a05102
a05102
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1504157
a05102
Upstream Status: nftables commit edcf3adcf4c4c
a05102
a05102
commit edcf3adcf4c4cf58cb0b965b984a512b12181a58
a05102
Author: Phil Sutter <phil@nwl.cc>
a05102
Date:   Thu Mar 1 15:00:29 2018 +0100
a05102
a05102
    evaluate: Fix memleak in stmt_reject_gen_dependency()
a05102
a05102
    The allocated payload expression is not used after returning from that
a05102
    function, so it needs to be freed again.
a05102
a05102
    Simple test case:
a05102
a05102
    | nft add rule inet t c reject with tcp reset
a05102
a05102
    Valgrind reports definitely lost 144 bytes.
a05102
a05102
    Signed-off-by: Phil Sutter <phil@nwl.cc>
a05102
    Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
a05102
---
a05102
 src/evaluate.c | 10 +++++++---
a05102
 1 file changed, 7 insertions(+), 3 deletions(-)
a05102
a05102
diff --git a/src/evaluate.c b/src/evaluate.c
a05102
index 25a7376..8552e4a 100644
a05102
--- a/src/evaluate.c
a05102
+++ b/src/evaluate.c
a05102
@@ -2136,8 +2136,10 @@ static int stmt_reject_gen_dependency(struct eval_ctx *ctx, struct stmt *stmt,
a05102
 	if (ret <= 0)
a05102
 		return ret;
a05102
 
a05102
-	if (payload_gen_dependency(ctx, payload, &nstmt) < 0)
a05102
-		return -1;
a05102
+	if (payload_gen_dependency(ctx, payload, &nstmt) < 0) {
a05102
+		ret = -1;
a05102
+		goto out;
a05102
+	}
a05102
 
a05102
 	/*
a05102
 	 * Unlike payload deps this adds the dependency at the beginning, i.e.
a05102
@@ -2148,7 +2150,9 @@ static int stmt_reject_gen_dependency(struct eval_ctx *ctx, struct stmt *stmt,
a05102
 	 * Otherwise we'd log things that won't be rejected.
a05102
 	 */
a05102
 	list_add(&nstmt->list, &ctx->rule->stmts);
a05102
-	return 0;
a05102
+out:
a05102
+	xfree(payload);
a05102
+	return ret;
a05102
 }
a05102
 
a05102
 static int stmt_evaluate_reject_inet_family(struct eval_ctx *ctx,
a05102
-- 
a05102
1.8.3.1
a05102