[PATCH v2 3/6] netdev_bandwidth_conf: Refractor virNetDevBandwidthParse()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Refractoring includes:
* removal of VIR_FREE
* inversion of the condition
* use of g_steal_pointer

Signed-off-by: Kristina Hanicova <khanicov@xxxxxxxxxx>
---
 src/conf/netdev_bandwidth_conf.c | 9 +++------
 src/util/virnetdevbandwidth.h    | 2 ++
 2 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/src/conf/netdev_bandwidth_conf.c b/src/conf/netdev_bandwidth_conf.c
index 1ff3785677..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,15 +197,12 @@ virNetDevBandwidthParse(virNetDevBandwidthPtr *bandwidth,
         }
     }
 
-    if (!def->in && !def->out)
-        VIR_FREE(def);
+    if (def->in || def->out)
+        *bandwidth = g_steal_pointer(&def);
 
-    *bandwidth = def;
-    def = NULL;
     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.29.2




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux