From: Phil Sutter Date: Fri, 11 Jun 2021 14:43:21 +0000 (+0200) Subject: netlink: Avoid memleak in error path of netlink_delinearize_set() X-Git-Tag: v1.0.0~73 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=accd7a346fd19f1ffc503b3f681323abf1157c1a;p=thirdparty%2Fnftables.git netlink: Avoid memleak in error path of netlink_delinearize_set() Duplicate string 'comment' later when the function does not fail anymore. Fixes: 0864c2d49ee8a ("src: add comment support for set declarations") Signed-off-by: Phil Sutter --- diff --git a/src/netlink.c b/src/netlink.c index e91b06e3..41cce337 100644 --- a/src/netlink.c +++ b/src/netlink.c @@ -867,7 +867,7 @@ struct set *netlink_delinearize_set(struct netlink_ctx *ctx, if (ud[NFTNL_UDATA_SET_DATA_TYPEOF]) typeof_expr_data = set_make_key(ud[NFTNL_UDATA_SET_DATA_TYPEOF]); if (ud[NFTNL_UDATA_SET_COMMENT]) - comment = xstrdup(nftnl_udata_get(ud[NFTNL_UDATA_SET_COMMENT])); + comment = nftnl_udata_get(ud[NFTNL_UDATA_SET_COMMENT]); } key = nftnl_set_get_u32(nls, NFTNL_SET_KEY_TYPE); @@ -905,7 +905,7 @@ struct set *netlink_delinearize_set(struct netlink_ctx *ctx, set->handle.set.name = xstrdup(nftnl_set_get_str(nls, NFTNL_SET_NAME)); set->automerge = automerge; if (comment) - set->comment = comment; + set->comment = xstrdup(comment); init_list_head(&set_parse_ctx.stmt_list);