void nftnl_chain_free(const struct nftnl_chain *c)
{
- if (c->table != NULL)
+ if (c->flags & (1 << NFTNL_CHAIN_TABLE))
xfree(c->table);
- if (c->type != NULL)
+ if (c->flags & (1 << NFTNL_CHAIN_TYPE))
xfree(c->type);
- if (c->dev != NULL)
+ if (c->flags & (1 << NFTNL_CHAIN_DEV))
xfree(c->dev);
xfree(c);
strncpy(c->name, data, NFT_CHAIN_MAXNAMELEN);
break;
case NFTNL_CHAIN_TABLE:
- if (c->table)
+ if (c->flags & (1 << NFTNL_CHAIN_TABLE))
xfree(c->table);
c->table = strdup(data);
c->family = *((uint32_t *)data);
break;
case NFTNL_CHAIN_TYPE:
- if (c->type)
+ if (c->flags & (1 << NFTNL_CHAIN_TYPE))
xfree(c->type);
c->type = strdup(data);
return -1;
break;
case NFTNL_CHAIN_DEV:
- if (c->dev)
+ if (c->flags & (1 << NFTNL_CHAIN_DEV))
xfree(c->dev);
c->dev = strdup(data);
c->flags |= (1 << NFTNL_CHAIN_NAME);
}
if (tb[NFTA_CHAIN_TABLE]) {
- xfree(c->table);
+ if (c->flags & (1 << NFTNL_CHAIN_TABLE))
+ xfree(c->table);
c->table = strdup(mnl_attr_get_str(tb[NFTA_CHAIN_TABLE]));
if (!c->table)
return -1;
c->flags |= (1 << NFTNL_CHAIN_HANDLE);
}
if (tb[NFTA_CHAIN_TYPE]) {
- xfree(c->type);
+ if (c->flags & (1 << NFTNL_CHAIN_TYPE))
+ xfree(c->type);
c->type = strdup(mnl_attr_get_str(tb[NFTA_CHAIN_TYPE]));
if (!c->type)
return -1;
imm->data.verdict = *((uint32_t *)data);
break;
case NFTNL_EXPR_IMM_CHAIN:
- if (imm->data.chain)
+ if (e->flags & (1 << NFTNL_EXPR_IMM_CHAIN))
xfree(imm->data.chain);
imm->data.chain = strdup(data);
switch(type) {
case NFTNL_EXPR_LOG_PREFIX:
- if (log->prefix)
+ if (log->flags & (1 << NFTNL_EXPR_LOG_PREFIX))
xfree(log->prefix);
log->prefix = strdup(data);
mt->rev = *((uint32_t *)data);
break;
case NFTNL_EXPR_MT_INFO:
- if (mt->data)
+ if (e->flags & (1 << NFTNL_EXPR_MT_INFO))
xfree(mt->data);
mt->data = data;
uint32_t len = mnl_attr_get_payload_len(tb[NFTA_MATCH_INFO]);
void *match_data;
- if (match->data)
+ if (e->flags & (1 << NFTNL_EXPR_MT_INFO))
xfree(match->data);
match_data = calloc(1, len);
tg->rev = *((uint32_t *)data);
break;
case NFTNL_EXPR_TG_INFO:
- if (tg->data)
+ if (e->flags & (1 << NFTNL_EXPR_TG_INFO))
xfree(tg->data);
tg->data = data;
list_for_each_entry_safe(e, tmp, &r->expr_list, head)
nftnl_expr_free(e);
- if (r->table != NULL)
+ if (r->flags & (1 << (NFTNL_RULE_TABLE)))
xfree(r->table);
- if (r->chain != NULL)
+ if (r->flags & (1 << (NFTNL_RULE_CHAIN)))
xfree(r->chain);
- if (r->user.data != NULL)
+ if (r->flags & (1 << (NFTNL_RULE_USERDATA)))
xfree(r->user.data);
xfree(r);
switch(attr) {
case NFTNL_RULE_TABLE:
- if (r->table)
+ if (r->flags & (1 << NFTNL_RULE_TABLE))
xfree(r->table);
r->table = strdup(data);
return -1;
break;
case NFTNL_RULE_CHAIN:
- if (r->chain)
+ if (r->flags & (1 << NFTNL_RULE_CHAIN))
xfree(r->chain);
r->chain = strdup(data);
r->position = *((uint64_t *)data);
break;
case NFTNL_RULE_USERDATA:
- if (r->user.data != NULL)
+ if (r->flags & (1 << NFTNL_RULE_USERDATA))
xfree(r->user.data);
r->user.data = malloc(data_len);
return -1;
if (tb[NFTA_RULE_TABLE]) {
- xfree(r->table);
+ if (r->flags & (1 << NFTNL_RULE_TABLE))
+ xfree(r->table);
r->table = strdup(mnl_attr_get_str(tb[NFTA_RULE_TABLE]));
if (!r->table)
return -1;
r->flags |= (1 << NFTNL_RULE_TABLE);
}
if (tb[NFTA_RULE_CHAIN]) {
- xfree(r->chain);
+ if (r->flags & (1 << NFTNL_RULE_CHAIN))
+ xfree(r->chain);
r->chain = strdup(mnl_attr_get_str(tb[NFTA_RULE_CHAIN]));
if (!r->chain)
return -1;
const void *udata =
mnl_attr_get_payload(tb[NFTA_RULE_USERDATA]);
- if (r->user.data)
+ if (r->flags & (1 << NFTNL_RULE_USERDATA))
xfree(r->user.data);
r->user.len = mnl_attr_get_payload_len(tb[NFTA_RULE_USERDATA]);
{
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) {
switch(attr) {
case NFTNL_SET_TABLE:
- if (s->table)
+ if (s->flags & (1 << NFTNL_SET_TABLE))
xfree(s->table);
s->table = strdup(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);
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;
void nftnl_set_elem_free(struct nftnl_set_elem *s)
{
- if (s->flags & (1 << NFTNL_SET_ELEM_CHAIN)) {
- if (s->data.chain) {
- xfree(s->data.chain);
- s->data.chain = NULL;
- }
- }
+ if (s->flags & (1 << NFTNL_SET_ELEM_CHAIN))
+ xfree(s->data.chain);
if (s->flags & (1 << NFTNL_SET_ELEM_EXPR))
nftnl_expr_free(s->expr);
s->data.verdict = *((uint32_t *)data);
break;
case NFTNL_SET_ELEM_CHAIN: /* NFTA_SET_ELEM_DATA */
- if (s->data.chain)
+ if (s->flags & (1 << NFTNL_SET_ELEM_CHAIN))
xfree(s->data.chain);
s->data.chain = strdup(data);
s->timeout = *((uint64_t *)data);
break;
case NFTNL_SET_ELEM_USERDATA: /* NFTA_SET_ELEM_USERDATA */
- if (s->user.data != NULL)
+ if (s->flags & (1 << NFTNL_SET_ELEM_USERDATA))
xfree(s->user.data);
s->user.data = malloc(data_len);
const void *udata =
mnl_attr_get_payload(tb[NFTA_SET_ELEM_USERDATA]);
- if (e->user.data)
+ if (e->flags & (1 << NFTNL_RULE_USERDATA))
xfree(e->user.data);
e->user.len = mnl_attr_get_payload_len(tb[NFTA_SET_ELEM_USERDATA]);
return -1;
if (tb[NFTA_SET_ELEM_LIST_TABLE]) {
- xfree(s->table);
+ if (s->flags & (1 << NFTNL_SET_TABLE))
+ xfree(s->table);
s->table =
strdup(mnl_attr_get_str(tb[NFTA_SET_ELEM_LIST_TABLE]));
if (!s->table)
s->flags |= (1 << NFTNL_SET_TABLE);
}
if (tb[NFTA_SET_ELEM_LIST_SET]) {
- xfree(s->name);
+ if (s->flags & (1 << NFTNL_SET_NAME))
+ xfree(s->name);
s->name =
strdup(mnl_attr_get_str(tb[NFTA_SET_ELEM_LIST_SET]));
if (!s->name)
switch (attr) {
case NFTNL_TABLE_NAME:
- if (t->name)
+ if (t->flags & (1 << NFTNL_TABLE_NAME))
xfree(t->name);
t->name = strdup(data);
return -1;
if (tb[NFTA_TABLE_NAME]) {
- xfree(t->name);
+ if (t->flags & (1 << NFTNL_TABLE_NAME))
+ xfree(t->name);
t->name = strdup(mnl_attr_get_str(tb[NFTA_TABLE_NAME]));
if (!t->name)
return -1;