Blob Blame History Raw
From 61e3dab3169af7add5fa131bb7414adf586d2997 Mon Sep 17 00:00:00 2001
From: Pablo Neira Ayuso <pablo@netfilter.org>
Date: Fri, 5 Apr 2019 15:35:36 +0200
Subject: [PATCH] src: missing destroy function in statement definitions

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
(cherry picked from commit 4ac11b890fe870d1c066783bccc235e1922dd431)

Conflicts:
-> Dropped changes to set_stmt_destroy() and map_stmt_destroy() due to
   missing commit a55ca1a24b7b2 ("src: integrate stateful expressions
   into sets and maps")

Signed-off-by: Phil Sutter <psutter@redhat.com>
---
 src/ct.c        | 12 ++++++++++++
 src/exthdr.c    |  7 +++++++
 src/meta.c      |  6 ++++++
 src/payload.c   |  7 +++++++
 src/statement.c | 19 +++++++++++++++++++
 src/xt.c        |  1 +
 6 files changed, 52 insertions(+)

diff --git a/src/ct.c b/src/ct.c
index f019f5af3e182..c2ca51494af60 100644
--- a/src/ct.c
+++ b/src/ct.c
@@ -440,11 +440,17 @@ static void ct_stmt_print(const struct stmt *stmt, struct output_ctx *octx)
 	expr_print(stmt->ct.expr, octx);
 }
 
+static void ct_stmt_destroy(struct stmt *stmt)
+{
+	expr_free(stmt->ct.expr);
+}
+
 static const struct stmt_ops ct_stmt_ops = {
 	.type		= STMT_CT,
 	.name		= "ct",
 	.print		= ct_stmt_print,
 	.json		= ct_stmt_json,
+	.destroy	= ct_stmt_destroy,
 };
 
 struct stmt *ct_stmt_alloc(const struct location *loc, enum nft_ct_keys key,
@@ -484,10 +490,16 @@ static void flow_offload_stmt_print(const struct stmt *stmt,
 	nft_print(octx, "flow offload @%s", stmt->flow.table_name);
 }
 
+static void flow_offload_stmt_destroy(struct stmt *stmt)
+{
+	xfree(stmt->flow.table_name);
+}
+
 static const struct stmt_ops flow_offload_stmt_ops = {
 	.type		= STMT_FLOW_OFFLOAD,
 	.name		= "flow_offload",
 	.print		= flow_offload_stmt_print,
+	.destroy	= flow_offload_stmt_destroy,
 };
 
 struct stmt *flow_offload_stmt_alloc(const struct location *loc,
diff --git a/src/exthdr.c b/src/exthdr.c
index cb0a58e8526a5..8602016f66477 100644
--- a/src/exthdr.c
+++ b/src/exthdr.c
@@ -104,11 +104,18 @@ static void exthdr_stmt_print(const struct stmt *stmt, struct output_ctx *octx)
 	expr_print(stmt->exthdr.val, octx);
 }
 
+static void exthdr_stmt_destroy(struct stmt *stmt)
+{
+	expr_free(stmt->exthdr.expr);
+	expr_free(stmt->exthdr.val);
+}
+
 static const struct stmt_ops exthdr_stmt_ops = {
 	.type		= STMT_EXTHDR,
 	.name		= "exthdr",
 	.print		= exthdr_stmt_print,
 	.json		= exthdr_stmt_json,
+	.destroy	= exthdr_stmt_destroy,
 };
 
 struct stmt *exthdr_stmt_alloc(const struct location *loc,
diff --git a/src/meta.c b/src/meta.c
index ff0cb122d7dfa..c1021febdefd4 100644
--- a/src/meta.c
+++ b/src/meta.c
@@ -604,11 +604,17 @@ static void meta_stmt_print(const struct stmt *stmt, struct output_ctx *octx)
 	expr_print(stmt->meta.expr, octx);
 }
 
+static void meta_stmt_destroy(struct stmt *stmt)
+{
+	expr_free(stmt->meta.expr);
+}
+
 static const struct stmt_ops meta_stmt_ops = {
 	.type		= STMT_META,
 	.name		= "meta",
 	.print		= meta_stmt_print,
 	.json		= meta_stmt_json,
+	.destroy	= meta_stmt_destroy,
 };
 
 struct stmt *meta_stmt_alloc(const struct location *loc, enum nft_meta_keys key,
diff --git a/src/payload.c b/src/payload.c
index 6517686cbfba5..42b055360848d 100644
--- a/src/payload.c
+++ b/src/payload.c
@@ -189,11 +189,18 @@ static void payload_stmt_print(const struct stmt *stmt, struct output_ctx *octx)
 	expr_print(stmt->payload.val, octx);
 }
 
+static void payload_stmt_destroy(struct stmt *stmt)
+{
+	expr_free(stmt->payload.expr);
+	expr_free(stmt->payload.val);
+}
+
 static const struct stmt_ops payload_stmt_ops = {
 	.type		= STMT_PAYLOAD,
 	.name		= "payload",
 	.print		= payload_stmt_print,
 	.json		= payload_stmt_json,
+	.destroy	= payload_stmt_destroy,
 };
 
 struct stmt *payload_stmt_alloc(const struct location *loc,
diff --git a/src/statement.c b/src/statement.c
index e9c9d648b0092..1b889e77cca20 100644
--- a/src/statement.c
+++ b/src/statement.c
@@ -134,6 +134,7 @@ static void meter_stmt_destroy(struct stmt *stmt)
 	expr_free(stmt->meter.key);
 	expr_free(stmt->meter.set);
 	stmt_free(stmt->meter.stmt);
+	xfree(stmt->meter.name);
 }
 
 static const struct stmt_ops meter_stmt_ops = {
@@ -226,11 +227,17 @@ static void objref_stmt_print(const struct stmt *stmt, struct output_ctx *octx)
 	expr_print(stmt->objref.expr, octx);
 }
 
+static void objref_stmt_destroy(struct stmt *stmt)
+{
+	expr_free(stmt->objref.expr);
+}
+
 static const struct stmt_ops objref_stmt_ops = {
 	.type		= STMT_OBJREF,
 	.name		= "objref",
 	.print		= objref_stmt_print,
 	.json		= objref_stmt_json,
+	.destroy	= objref_stmt_destroy,
 };
 
 struct stmt *objref_stmt_alloc(const struct location *loc)
@@ -435,11 +442,17 @@ static void queue_stmt_print(const struct stmt *stmt, struct output_ctx *octx)
 
 }
 
+static void queue_stmt_destroy(struct stmt *stmt)
+{
+	expr_free(stmt->queue.queue);
+}
+
 static const struct stmt_ops queue_stmt_ops = {
 	.type		= STMT_QUEUE,
 	.name		= "queue",
 	.print		= queue_stmt_print,
 	.json		= queue_stmt_json,
+	.destroy	= queue_stmt_destroy,
 };
 
 struct stmt *queue_stmt_alloc(const struct location *loc)
@@ -511,11 +524,17 @@ static void reject_stmt_print(const struct stmt *stmt, struct output_ctx *octx)
 	}
 }
 
+static void reject_stmt_destroy(struct stmt *stmt)
+{
+	expr_free(stmt->reject.expr);
+}
+
 static const struct stmt_ops reject_stmt_ops = {
 	.type		= STMT_REJECT,
 	.name		= "reject",
 	.print		= reject_stmt_print,
 	.json		= reject_stmt_json,
+	.destroy	= reject_stmt_destroy,
 };
 
 struct stmt *reject_stmt_alloc(const struct location *loc)
diff --git a/src/xt.c b/src/xt.c
index 74763d58cafd7..298a94d51e8a0 100644
--- a/src/xt.c
+++ b/src/xt.c
@@ -92,6 +92,7 @@ void xt_stmt_release(const struct stmt *stmt)
 		break;
 	}
 	xfree(stmt->xt.entry);
+	xfree(stmt->xt.name);
 }
 
 static void *xt_entry_alloc(struct xt_stmt *xt, uint32_t af)
-- 
2.21.0