Wrap the code to release the list of commands in a helper function, then use it to consolidate codebase. Signed-off-by: Pablo Neira Ayuso --- src/libnftables.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/libnftables.c b/src/libnftables.c index e3218da9f48f..46d9c0df590b 100644 --- a/src/libnftables.c +++ b/src/libnftables.c @@ -605,11 +605,23 @@ static int nft_evaluate(struct nft_ctx *nft, struct list_head *msgs, return 0; } +static void nft_run_cmd_release(struct nft_ctx *nft, + struct list_head *msgs, + struct list_head *cmds) +{ + struct cmd *cmd, *next; + + erec_print_list(&nft->output, msgs, nft->debug_mask); + list_for_each_entry_safe(cmd, next, cmds, list) { + list_del(&cmd->list); + cmd_free(cmd); + } +} + EXPORT_SYMBOL(nft_run_cmd_from_buffer); int nft_run_cmd_from_buffer(struct nft_ctx *nft, const char *buf) { int rc = -EINVAL, parser_rc; - struct cmd *cmd, *next; LIST_HEAD(msgs); LIST_HEAD(cmds); char *nlbuf; @@ -646,11 +658,8 @@ int nft_run_cmd_from_buffer(struct nft_ctx *nft, const char *buf) if (nft_netlink(nft, &cmds, &msgs) != 0) rc = -1; err: - erec_print_list(&nft->output, &msgs, nft->debug_mask); - list_for_each_entry_safe(cmd, next, &cmds, list) { - list_del(&cmd->list); - cmd_free(cmd); - } + nft_run_cmd_release(nft, &msgs, &cmds); + iface_cache_release(); if (nft->scanner) { scanner_destroy(nft); @@ -739,7 +748,6 @@ static struct error_record *filename_is_useable(struct nft_ctx *nft, const char static int __nft_run_cmd_from_filename(struct nft_ctx *nft, const char *filename) { struct error_record *erec; - struct cmd *cmd, *next; int rc, parser_rc; LIST_HEAD(msgs); LIST_HEAD(cmds); @@ -783,11 +791,8 @@ static int __nft_run_cmd_from_filename(struct nft_ctx *nft, const char *filename if (nft_netlink(nft, &cmds, &msgs) != 0) rc = -1; err: - erec_print_list(&nft->output, &msgs, nft->debug_mask); - list_for_each_entry_safe(cmd, next, &cmds, list) { - list_del(&cmd->list); - cmd_free(cmd); - } + nft_run_cmd_release(nft, &msgs, &cmds); + iface_cache_release(); if (nft->scanner) { scanner_destroy(nft); -- 2.47.3