]> git.ipfire.org Git - thirdparty/libnftnl.git/commitdiff
src: xml: don't duplicate string in nft_table_xml_parse
authorPablo Neira Ayuso <pablo@netfilter.org>
Wed, 14 Aug 2013 09:10:58 +0000 (11:10 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Wed, 14 Aug 2013 09:14:11 +0000 (11:14 +0200)
With this patch, nft_table_xml_parse does not duplicate the string
anymore, which is what most callers seem to need. This fixes memleaks
in several places in the code. Thus, this patch also adapts the code
to duplicate it when needed.

Based on patch from Arturo Borrero.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
src/chain.c
src/expr/log.c
src/mxml.c
src/rule.c
src/set.c
src/table.c

index e2296d3cde67430012b48e6106268903e56eb1fe..97f6d95428009571757140fb7daa959e4a36e679 100644 (file)
@@ -597,7 +597,6 @@ static int nft_chain_xml_parse(struct nft_chain *c, char *xml)
                goto err;
 
        strncpy(c->name, name, NFT_CHAIN_MAXNAMELEN);
-       xfree(name);
        c->flags |= (1 << NFT_CHAIN_ATTR_NAME);
 
        if (nft_mxml_num_parse(tree, "handle", MXML_DESCEND_FIRST, BASE_DEC,
@@ -650,8 +649,6 @@ static int nft_chain_xml_parse(struct nft_chain *c, char *xml)
                goto err;
 
        hooknum = nft_str2hooknum(hooknum_str);
-       xfree(hooknum_str);
-
        if (hooknum < 0)
                goto err;
 
index 14785fd896e632664c08efbd5a47267345384460..291502bd0ac1ece2d6b6d4ef417283ace97d6868 100644 (file)
@@ -162,7 +162,7 @@ static int nft_rule_expr_log_xml_parse(struct nft_rule_expr *e, mxml_node_t *tre
        if (prefix == NULL)
                return -1;
 
-       log->prefix = prefix;
+       log->prefix = strdup(prefix);
        e->flags |= (1 << NFT_EXPR_LOG_PREFIX);
 
        if (nft_mxml_num_parse(tree, "group", MXML_DESCEND_FIRST, BASE_DEC,
index b5de1536dfb8a3fd2327abadc8d26da8e5aa2991..b77936aec67b3bb19b86db6ddf6473564aaa24f1 100644 (file)
@@ -163,7 +163,7 @@ const char *nft_mxml_str_parse(mxml_node_t *tree, const char *node_name,
                return NULL;
        }
 
-       return strdup(node->child->value.opaque);
+       return node->child->value.opaque;
 }
 
 int nft_mxml_family_parse(mxml_node_t *tree, const char *node_name,
@@ -177,8 +177,6 @@ int nft_mxml_family_parse(mxml_node_t *tree, const char *node_name,
                return -1;
 
        family = nft_str2family(family_str);
-       xfree(family_str);
-
        if (family < 0)
                errno = EAFNOSUPPORT;
 
index 4b5ffa6471fb7d799ce3a14e6d615a0749c88484..c3cdb84d90b8fcb4d1fa60776f57a8c2b30ad249 100644 (file)
@@ -514,7 +514,7 @@ static int nft_rule_xml_parse(struct nft_rule *r, char *xml)
        if (r->table)
                xfree(r->table);
 
-       r->table = table;
+       r->table = strdup(table);
        r->flags |= (1 << NFT_RULE_ATTR_TABLE);
 
        chain = nft_mxml_str_parse(tree, "chain", MXML_DESCEND_FIRST);
@@ -526,7 +526,7 @@ static int nft_rule_xml_parse(struct nft_rule *r, char *xml)
        if (r->chain)
                xfree(r->chain);
 
-       r->chain = chain;
+       r->chain = strdup(chain);
        r->flags |= (1 << NFT_RULE_ATTR_CHAIN);
 
        if (nft_mxml_num_parse(tree, "handle", MXML_DESCEND_FIRST, BASE_DEC,
index 97856b35eb3f9f6206f084918c58c0241f5c3ab1..ff34bf5ee8f568e49a3346e11f35127a3e91fa44 100644 (file)
--- a/src/set.c
+++ b/src/set.c
@@ -328,7 +328,7 @@ static int nft_set_xml_parse(struct nft_set *s, char *xml)
        if (s->name)
                xfree(s->name);
 
-       s->name = name;
+       s->name = strdup(name);
        s->flags |= (1 << NFT_SET_ATTR_NAME);
 
        table = nft_mxml_str_parse(tree, "table", MXML_DESCEND_FIRST);
@@ -338,7 +338,7 @@ static int nft_set_xml_parse(struct nft_set *s, char *xml)
        if (s->table)
                xfree(s->table);
 
-       s->table = table;
+       s->table = strdup(table);
        s->flags |= (1 << NFT_SET_ATTR_TABLE);
 
        family = nft_mxml_family_parse(tree, "family", MXML_DESCEND_FIRST);
index 1fa0dac9f4735eacb14bb3804c5d54fc01c7295b..26bf60d7ef3056a02fa05b29b1433200a1b4dadd 100644 (file)
@@ -239,7 +239,7 @@ static int nft_table_xml_parse(struct nft_table *t, char *xml)
        if (t->name)
                xfree(t->name);
 
-       t->name = name;
+       t->name = strdup(name);
        t->flags |= (1 << NFT_TABLE_ATTR_NAME);
 
        family = nft_mxml_family_parse(tree, "family", MXML_DESCEND_FIRST);