]> git.proxmox.com Git - mirror_lxc.git/commitdiff
confile_utils: cleanup lxc_remove_nic_by_idx()
authorChristian Brauner <christian.brauner@ubuntu.com>
Wed, 9 Dec 2020 08:49:29 +0000 (09:49 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Thu, 10 Dec 2020 19:39:50 +0000 (20:39 +0100)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/confile_utils.c

index 531e2eaf88a8658787624b9bfafffb18d3ffa521..97370e549675516dc3584e1a07f8331e24f34639 100644 (file)
@@ -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)