]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
netdev_bandwidth_conf: Refractor virNetDevBandwidthParse()
authorKristina Hanicova <khanicov@redhat.com>
Wed, 3 Mar 2021 10:48:17 +0000 (11:48 +0100)
committerJán Tomko <jtomko@redhat.com>
Thu, 4 Mar 2021 16:30:04 +0000 (17:30 +0100)
Refractoring includes:
* removal of VIR_FREE
* inversion of the condition

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
src/conf/netdev_bandwidth_conf.c
src/util/virnetdevbandwidth.h

index 53cb6978bc7dc7aabc469aeddecb0a8652429a74..81590efe6d3c05c29b3f731d481c3ef2870ad415 100644 (file)
@@ -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;
 }
 
index 871d0c962c6ef6a909f813f670c810408ccc60d7..fff83222a9a0a8b35b51f2b2bbb9f4f18d46facb 100644 (file)
@@ -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,