diff options
author | Pablo Neira Ayuso <pablo@netfilter.org> | 2013-08-14 11:10:58 +0200 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2013-08-14 11:14:11 +0200 |
commit | a5c387def7981fd5b2e48759d3d1ca489cdfefcf (patch) | |
tree | 91cdfee76d0c0abd7435fe4a0aac7a793f2e4670 | |
parent | 03886d5908fe4ba44a056d8297cc7b48c91a8f15 (diff) |
src: xml: don't duplicate string in nft_table_xml_parse
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>
-rw-r--r-- | src/chain.c | 3 | ||||
-rw-r--r-- | src/expr/log.c | 2 | ||||
-rw-r--r-- | src/mxml.c | 4 | ||||
-rw-r--r-- | src/rule.c | 4 | ||||
-rw-r--r-- | src/set.c | 4 | ||||
-rw-r--r-- | src/table.c | 2 |
6 files changed, 7 insertions, 12 deletions
diff --git a/src/chain.c b/src/chain.c index e2296d3..97f6d95 100644 --- a/src/chain.c +++ b/src/chain.c @@ -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; diff --git a/src/expr/log.c b/src/expr/log.c index 14785fd..291502b 100644 --- a/src/expr/log.c +++ b/src/expr/log.c @@ -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, @@ -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; @@ -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, @@ -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); diff --git a/src/table.c b/src/table.c index 1fa0dac..26bf60d 100644 --- a/src/table.c +++ b/src/table.c @@ -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); |