diff options
| author | Phil Sutter <phil@nwl.cc> | 2024-10-02 16:44:49 +0200 |
|---|---|---|
| committer | Phil Sutter <phil@nwl.cc> | 2025-10-18 21:11:27 +0200 |
| commit | 5a54b99859fd52d8c7e866b57f6d8fac3e20a78f (patch) | |
| tree | 6f4638c243b241886fdd0bb8916f074bcd0d12ad /src/object.c | |
| parent | 6f24a13a19b8690444564f50e1866fae5abf7687 (diff) | |
Wrap the common parsing of string attributes in a function. Apart from
slightly reducing code size, this unifies callers in conditional freeing
of the field in case it was set before (missing in twelve spots) and
error checking for failing strdup()-calls (missing in four spots).
Signed-off-by: Phil Sutter <phil@nwl.cc>
Acked-by: Florian Westphal <fw@strlen.de>
Diffstat (limited to 'src/object.c')
| -rw-r--r-- | src/object.c | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/src/object.c b/src/object.c index 275a202..3d358cc 100644 --- a/src/object.c +++ b/src/object.c @@ -344,14 +344,12 @@ int nftnl_obj_nlmsg_parse(const struct nlmsghdr *nlh, struct nftnl_obj *obj) if (mnl_attr_parse(nlh, sizeof(*nfg), nftnl_obj_parse_attr_cb, tb) < 0) return -1; - if (tb[NFTA_OBJ_TABLE]) { - obj->table = strdup(mnl_attr_get_str(tb[NFTA_OBJ_TABLE])); - obj->flags |= (1 << NFTNL_OBJ_TABLE); - } - if (tb[NFTA_OBJ_NAME]) { - obj->name = strdup(mnl_attr_get_str(tb[NFTA_OBJ_NAME])); - obj->flags |= (1 << NFTNL_OBJ_NAME); - } + if (nftnl_parse_str_attr(tb[NFTA_OBJ_TABLE], NFTNL_OBJ_TABLE, + &obj->table, &obj->flags) < 0) + return -1; + if (nftnl_parse_str_attr(tb[NFTA_OBJ_NAME], NFTNL_OBJ_NAME, + &obj->name, &obj->flags) < 0) + return -1; if (tb[NFTA_OBJ_TYPE]) { uint32_t type = ntohl(mnl_attr_get_u32(tb[NFTA_OBJ_TYPE])); |
