From bcb63a3bdcc7b22376ce60b7833958cf6cddf702 Mon Sep 17 00:00:00 2001 From: Kristina Hanicova Date: Wed, 3 Mar 2021 11:48:17 +0100 Subject: [PATCH] netdev_bandwidth_conf: Refractor virNetDevBandwidthParse() MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Refractoring includes: * removal of VIR_FREE * inversion of the condition Signed-off-by: Kristina Hanicova Reviewed-by: Ján Tomko Signed-off-by: Ján Tomko --- src/conf/netdev_bandwidth_conf.c | 8 +++----- src/util/virnetdevbandwidth.h | 2 ++ 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/conf/netdev_bandwidth_conf.c b/src/conf/netdev_bandwidth_conf.c index 53cb6978bc..81590efe6d 100644 --- a/src/conf/netdev_bandwidth_conf.c +++ b/src/conf/netdev_bandwidth_conf.c @@ -111,7 +111,7 @@ virNetDevBandwidthParse(virNetDevBandwidthPtr *bandwidth, bool allowFloor) { int ret = -1; - virNetDevBandwidthPtr def = NULL; + g_autoptr(virNetDevBandwidth) def = NULL; xmlNodePtr cur; xmlNodePtr in = NULL, out = NULL; g_autofree char *class_id_prop = NULL; @@ -197,14 +197,12 @@ virNetDevBandwidthParse(virNetDevBandwidthPtr *bandwidth, } } - if (!def->in && !def->out) - VIR_FREE(def); + if (def->in || def->out) + *bandwidth = g_steal_pointer(&def); - *bandwidth = g_steal_pointer(&def); ret = 0; cleanup: - virNetDevBandwidthFree(def); return ret; } diff --git a/src/util/virnetdevbandwidth.h b/src/util/virnetdevbandwidth.h index 871d0c962c..fff83222a9 100644 --- a/src/util/virnetdevbandwidth.h +++ b/src/util/virnetdevbandwidth.h @@ -38,6 +38,8 @@ struct _virNetDevBandwidth { void virNetDevBandwidthFree(virNetDevBandwidthPtr def); +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virNetDevBandwidth, virNetDevBandwidthFree); + int virNetDevBandwidthSet(const char *ifname, const virNetDevBandwidth *bandwidth, bool hierarchical_class, -- 2.47.2