From: Christian Brauner Date: Wed, 9 Dec 2020 08:46:22 +0000 (+0100) Subject: confile_utils: cleanup lxc_network_add() X-Git-Tag: lxc-5.0.0~330^2~45 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1e323af6dc8ab49cf485838f366f73e334cd4616;p=thirdparty%2Flxc.git confile_utils: cleanup lxc_network_add() Signed-off-by: Christian Brauner --- diff --git a/src/lxc/confile_utils.c b/src/lxc/confile_utils.c index 445456413..a90658b07 100644 --- a/src/lxc/confile_utils.c +++ b/src/lxc/confile_utils.c @@ -160,13 +160,13 @@ bool lxc_config_value_empty(const char *value) struct lxc_netdev *lxc_network_add(struct lxc_list *networks, int idx, bool tail) { - struct lxc_list *newlist; - struct lxc_netdev *netdev = NULL; + __do_free struct lxc_list *newlist = NULL; + __do_free struct lxc_netdev *netdev = NULL; /* network does not exist */ netdev = malloc(sizeof(*netdev)); if (!netdev) - return NULL; + return ret_set_errno(NULL, ENOMEM); memset(netdev, 0, sizeof(*netdev)); lxc_list_init(&netdev->ipv4); @@ -177,10 +177,8 @@ struct lxc_netdev *lxc_network_add(struct lxc_list *networks, int idx, bool tail /* prepare new list */ newlist = malloc(sizeof(*newlist)); - if (!newlist) { - free(netdev); - return NULL; - } + if (!newlist) + return ret_set_errno(NULL, ENOMEM); lxc_list_init(newlist); newlist->elem = netdev; @@ -189,8 +187,9 @@ struct lxc_netdev *lxc_network_add(struct lxc_list *networks, int idx, bool tail lxc_list_add_tail(networks, newlist); else lxc_list_add(networks, newlist); + move_ptr(newlist); - return netdev; + return move_ptr(netdev); } /* Takes care of finding the correct netdev struct in the networks list or