[PATCH 3/4] Use g_autoptr instead of virNetDevBandwidthFree where possible

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

 



In files: netdev_bandwidth_conf: in virNetDevBandwidthParse(),
bridge_driver: in networkPortSetParameters(), qemu_driver: in
qemuDomainSetInterfaceParameters(), test_driver: in
testDomainSetInterfaceParameters(), virnetdevbandwidthtest: in
testVirNetDevBandwidthSet()

Signed-off-by: Kristina Hanicova <khanicov@xxxxxxxxxx>
---
 src/conf/netdev_bandwidth_conf.c |  9 +++------
 src/network/bridge_driver.c      |  6 ++----
 src/qemu/qemu_driver.c           | 11 ++++-------
 src/test/test_driver.c           |  3 +--
 src/util/virnetdevbandwidth.h    |  2 ++
 tests/virnetdevbandwidthtest.c   |  3 +--
 6 files changed, 13 insertions(+), 21 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/network/bridge_driver.c b/src/network/bridge_driver.c
index 519a473995..b29c37ef4c 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -5397,7 +5397,7 @@ networkPortSetParameters(virNetworkPortPtr port,
     virNetworkObjPtr obj;
     virNetworkDefPtr def;
     virNetworkPortDefPtr portdef;
-    virNetDevBandwidthPtr bandwidth = NULL;
+    g_autoptr(virNetDevBandwidth) bandwidth = NULL;
     g_autofree char *dir = NULL;
     int ret = -1;
     size_t i;
@@ -5466,15 +5466,13 @@ networkPortSetParameters(virNetworkPortPtr port,
         goto cleanup;
 
     virNetDevBandwidthFree(portdef->bandwidth);
-    portdef->bandwidth = bandwidth;
-    bandwidth = NULL;
+    portdef->bandwidth = g_steal_pointer(&bandwidth);
 
     if (virNetworkPortDefSaveStatus(portdef, dir) < 0)
         goto cleanup;
 
     ret = 0;
  cleanup:
-    virNetDevBandwidthFree(bandwidth);
     virNetworkObjEndAPI(&obj);
     return ret;
 }
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index b9bbdf8d48..2a191232a6 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -10207,7 +10207,8 @@ qemuDomainSetInterfaceParameters(virDomainPtr dom,
     virDomainDefPtr persistentDef;
     int ret = -1;
     virDomainNetDefPtr net = NULL, persistentNet = NULL;
-    virNetDevBandwidthPtr bandwidth = NULL, newBandwidth = NULL;
+    g_autoptr(virNetDevBandwidth) bandwidth = NULL;
+    g_autoptr(virNetDevBandwidth) newBandwidth = NULL;
     g_autoptr(virQEMUDriverConfig) cfg = NULL;
     bool inboundSpecified = false, outboundSpecified = false;
     int actualType;
@@ -10375,8 +10376,7 @@ qemuDomainSetInterfaceParameters(virDomainPtr dom,
 
         virNetDevBandwidthFree(net->bandwidth);
         if (newBandwidth->in || newBandwidth->out) {
-            net->bandwidth = newBandwidth;
-            newBandwidth = NULL;
+            net->bandwidth = g_steal_pointer(&newBandwidth);
         } else {
             net->bandwidth = NULL;
         }
@@ -10394,8 +10394,7 @@ qemuDomainSetInterfaceParameters(virDomainPtr dom,
 
     if (persistentNet) {
         if (!persistentNet->bandwidth) {
-            persistentNet->bandwidth = bandwidth;
-            bandwidth = NULL;
+            persistentNet->bandwidth = g_steal_pointer(&bandwidth);
         } else {
             if (bandwidth->in) {
                 VIR_FREE(persistentNet->bandwidth->in);
@@ -10423,8 +10422,6 @@ qemuDomainSetInterfaceParameters(virDomainPtr dom,
     qemuDomainObjEndJob(driver, vm);
 
  cleanup:
-    virNetDevBandwidthFree(bandwidth);
-    virNetDevBandwidthFree(newBandwidth);
     virDomainObjEndAPI(&vm);
     return ret;
 }
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index bca1297d1d..0ac03de127 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -3446,7 +3446,7 @@ testDomainSetInterfaceParameters(virDomainPtr dom,
     virDomainObjPtr vm = NULL;
     virDomainDefPtr def;
     virDomainNetDefPtr net = NULL;
-    virNetDevBandwidthPtr bandwidth = NULL;
+    g_autoptr(virNetDevBandwidth) bandwidth = NULL;
     bool inboundSpecified = false;
     bool outboundSpecified = false;
     size_t i;
@@ -3536,7 +3536,6 @@ testDomainSetInterfaceParameters(virDomainPtr dom,
 
     ret = 0;
  cleanup:
-    virNetDevBandwidthFree(bandwidth);
     virDomainObjEndAPI(&vm);
     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,
diff --git a/tests/virnetdevbandwidthtest.c b/tests/virnetdevbandwidthtest.c
index 5cbdd6ffea..2e76af3d0c 100644
--- a/tests/virnetdevbandwidthtest.c
+++ b/tests/virnetdevbandwidthtest.c
@@ -69,7 +69,7 @@ testVirNetDevBandwidthSet(const void *data)
     int ret = -1;
     const struct testSetStruct *info = data;
     const char *iface = info->iface;
-    virNetDevBandwidthPtr band = NULL;
+    g_autoptr(virNetDevBandwidth) band = NULL;
     g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
     char *actual_cmd = NULL;
 
@@ -98,7 +98,6 @@ testVirNetDevBandwidthSet(const void *data)
     ret = 0;
  cleanup:
     virCommandSetDryRun(NULL, NULL, NULL);
-    virNetDevBandwidthFree(band);
     VIR_FREE(actual_cmd);
     return ret;
 }
-- 
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