Skip to contentSkip to conversation

expr: objref: add nftnl_expr_objref_free() to release object name

PATCH New Pablo Neira Ayuso 1 participant 1 message May 5, 2020 netfilter

lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH 1/1 expr: objref: add nftnl_expr_objref_free() to release object name

==4876==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 9 byte(s) in 1 object(s) allocated from:

    #0 0x7f4e2c16b810 in strdup (/usr/lib/x86_64-linux-gnu/libasan.so.5+0x3a810)
    #1 0x7f4e2a39906f in nftnl_expr_objref_set expr/objref.c:45
    #2 0x7f4e2a39906f in nftnl_expr_objref_set expr/objref.c:35
---
 src/expr/objref.c | 8 ++++++++
 1 file changed, 8 insertions(+)
src/expr/objref.c +8 -0
index 7388b18ac929..d3dd17ee788c 100644
@@ -187,6 +187,13 @@ static int nftnl_expr_objref_snprintf_default(char *buf, size_t len,
 				objref->imm.type, objref->imm.name);
 }
 
+static void nftnl_expr_objref_free(const struct nftnl_expr *e)
+{
+	struct nftnl_expr_objref *objref = nftnl_expr_data(e);
+
+	xfree(objref->imm.name);
+}
+
 static int nftnl_expr_objref_snprintf(char *buf, size_t len, uint32_t type,
 				      uint32_t flags,
 				      const struct nftnl_expr *e)
@@ -206,6 +213,7 @@ struct expr_ops expr_ops_objref = {
 	.name		= "objref",
 	.alloc_len	= sizeof(struct nftnl_expr_objref),
 	.max_attr	= NFTA_OBJREF_MAX,
+	.free		= nftnl_expr_objref_free,
 	.set		= nftnl_expr_objref_set,
 	.get		= nftnl_expr_objref_get,
 	.parse		= nftnl_expr_objref_parse,
Signature · 1 line
2.20.1