From: Christian Brauner Date: Wed, 9 Dec 2020 08:49:29 +0000 (+0100) Subject: confile_utils: cleanup lxc_remove_nic_by_idx() X-Git-Tag: lxc-5.0.0~330^2~43 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=06db6101d9ec5f6736617596a7e962ad8519ce95;p=thirdparty%2Flxc.git confile_utils: cleanup lxc_remove_nic_by_idx() Signed-off-by: Christian Brauner --- diff --git a/src/lxc/confile_utils.c b/src/lxc/confile_utils.c index 531e2eaf8..97370e549 100644 --- a/src/lxc/confile_utils.c +++ b/src/lxc/confile_utils.c @@ -408,6 +408,9 @@ static void lxc_free_netdev(struct lxc_netdev *netdev) { struct lxc_list *cur, *next; + if (!netdev) + return; + free(netdev->upscript); free(netdev->downscript); free(netdev->hwaddr); @@ -449,11 +452,12 @@ static void lxc_free_netdev(struct lxc_netdev *netdev) free(netdev); } +define_cleanup_function(struct lxc_netdev *, lxc_free_netdev); + bool lxc_remove_nic_by_idx(struct lxc_conf *conf, unsigned int idx) { + call_cleaner(lxc_free_netdev) struct lxc_netdev *netdev = NULL; struct lxc_list *cur, *next; - struct lxc_netdev *netdev; - bool found = false; lxc_list_for_each_safe(cur, &conf->network, next) { netdev = cur->elem; @@ -461,17 +465,11 @@ bool lxc_remove_nic_by_idx(struct lxc_conf *conf, unsigned int idx) continue; lxc_list_del(cur); - found = true; - break; + free(cur); + return true; } - if (!found) - return false; - - lxc_free_netdev(netdev); - free(cur); - - return true; + return false; } void lxc_free_networks(struct lxc_list *networks)