From 50b175dbd598e80a0e67606645d1fa3c9be6ce01 Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Fri, 10 Jun 2016 16:45:48 +0200 Subject: src: check for flags before releasing attributes Now that unsetters don't set pointers to NULL, check if the attribute is set before trying to release it. Signed-off-by: Pablo Neira Ayuso --- src/set.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'src/set.c') diff --git a/src/set.c b/src/set.c index 46a0007..08d5797 100644 --- a/src/set.c +++ b/src/set.c @@ -44,9 +44,9 @@ void nftnl_set_free(const struct nftnl_set *s) { struct nftnl_set_elem *elem, *tmp; - if (s->table != NULL) + if (s->flags & (1 << NFTNL_SET_TABLE)) xfree(s->table); - if (s->name != NULL) + if (s->flags & (1 << NFTNL_SET_NAME)) xfree(s->name); list_for_each_entry_safe(elem, tmp, &s->element_list, head) { @@ -116,7 +116,7 @@ int nftnl_set_set_data(struct nftnl_set *s, uint16_t attr, const void *data, switch(attr) { case NFTNL_SET_TABLE: - if (s->table) + if (s->flags & (1 << NFTNL_SET_TABLE)) xfree(s->table); s->table = strdup(data); @@ -124,7 +124,7 @@ int nftnl_set_set_data(struct nftnl_set *s, uint16_t attr, const void *data, return -1; break; case NFTNL_SET_NAME: - if (s->name) + if (s->flags & (1 << NFTNL_SET_NAME)) xfree(s->name); s->name = strdup(data); @@ -439,14 +439,16 @@ int nftnl_set_nlmsg_parse(const struct nlmsghdr *nlh, struct nftnl_set *s) return -1; if (tb[NFTA_SET_TABLE]) { - xfree(s->table); + if (s->flags & (1 << NFTNL_SET_TABLE)) + xfree(s->table); s->table = strdup(mnl_attr_get_str(tb[NFTA_SET_TABLE])); if (!s->table) return -1; s->flags |= (1 << NFTNL_SET_TABLE); } if (tb[NFTA_SET_NAME]) { - xfree(s->name); + if (s->flags & (1 << NFTNL_SET_NAME)) + xfree(s->name); s->name = strdup(mnl_attr_get_str(tb[NFTA_SET_NAME])); if (!s->name) return -1; -- cgit v1.2.3