From: Christian Brauner Date: Tue, 8 Dec 2020 17:51:01 +0000 (+0100) Subject: confile: cleanup clr_config_net_nic() X-Git-Tag: lxc-5.0.0~330^2~93 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ec35c656a8d44e845f6b5bf3580554bc851a158d;p=thirdparty%2Flxc.git confile: cleanup clr_config_net_nic() Signed-off-by: Christian Brauner --- diff --git a/src/lxc/confile.c b/src/lxc/confile.c index cb1add096..f376133e8 100644 --- a/src/lxc/confile.c +++ b/src/lxc/confile.c @@ -5152,16 +5152,16 @@ static int set_config_net_nic(const char *key, const char *value, static int clr_config_net_nic(const char *key, struct lxc_conf *lxc_conf, void *data) { + __do_free char *deindexed_key = NULL; + ssize_t idx = -1; int ret; const char *idxstring; struct lxc_config_t *config; struct lxc_netdev *netdev; - ssize_t idx = -1; - char *deindexed_key = NULL; idxstring = key + 8; if (!isdigit(*idxstring)) - return -1; + return ret_errno(EINVAL); /* The left conjunct is pretty self-explanatory. The right conjunct * checks whether the two pointers are equal. If they are we know that @@ -5171,8 +5171,9 @@ static int clr_config_net_nic(const char *key, struct lxc_conf *lxc_conf, if (isdigit(*idxstring) && (strrchr(key, '.') == (idxstring - 1))) { unsigned int rmnetdevidx; - if (lxc_safe_uint(idxstring, &rmnetdevidx) < 0) - return -1; + ret = lxc_safe_uint(idxstring, &rmnetdevidx); + if (ret < 0) + return ret; /* Remove network from network list. */ lxc_remove_nic_by_idx(lxc_conf, rmnetdevidx); @@ -5181,18 +5182,13 @@ static int clr_config_net_nic(const char *key, struct lxc_conf *lxc_conf, config = get_network_config_ops(key, lxc_conf, &idx, &deindexed_key); if (!config || idx < 0) - return -1; + return -errno; netdev = lxc_get_netdev_by_idx(lxc_conf, (unsigned int)idx, false); - if (!netdev) { - free(deindexed_key); - return -1; - } - - ret = config->clr(deindexed_key, lxc_conf, netdev); - free(deindexed_key); + if (!netdev) + return ret_errno(EINVAL); - return ret; + return config->clr(deindexed_key, lxc_conf, netdev); } static int clr_config_net_type(const char *key, struct lxc_conf *lxc_conf,