[PATCH v2 8/9] qemu_driver: use VIR_AUTOFREE() with strings 3/3

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

 



Using VIR_AUTOFREE() in all strings of qemu_driver.c make the code
a bit tidier and smaller, sparing VIR_FREE() calls and sometimes a
whole 'cleanup' label.

This is the last part of this change.

Signed-off-by: Daniel Henrique Barboza <danielhb413@xxxxxxxxx>
---
 src/qemu/qemu_driver.c | 99 +++++++++++++++---------------------------
 1 file changed, 34 insertions(+), 65 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 05736fbd26..aac952363e 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -11943,7 +11943,7 @@ qemuDomainMemoryPeek(virDomainPtr dom,
 {
     virQEMUDriverPtr driver = dom->conn->privateData;
     virDomainObjPtr vm;
-    char *tmp = NULL;
+    VIR_AUTOFREE(char *) tmp = NULL;
     int fd = -1, ret = -1;
     qemuDomainObjPrivatePtr priv;
     VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = NULL;
@@ -12015,7 +12015,6 @@ qemuDomainMemoryPeek(virDomainPtr dom,
     VIR_FORCE_CLOSE(fd);
     if (tmp)
         unlink(tmp);
-    VIR_FREE(tmp);
     virDomainObjEndAPI(&vm);
     return ret;
 }
@@ -12181,7 +12180,7 @@ qemuStorageLimitsRefresh(virQEMUDriverPtr driver,
     int ret = -1;
     int fd = -1;
     struct stat sb;
-    char *buf = NULL;
+    VIR_AUTOFREE(char *) buf = NULL;
     ssize_t len;
 
     if ((rc = qemuDomainStorageOpenStat(driver, cfg, vm, src, &fd, &sb,
@@ -12217,7 +12216,6 @@ qemuStorageLimitsRefresh(virQEMUDriverPtr driver,
     ret = 1;
 
  cleanup:
-    VIR_FREE(buf);
     qemuDomainStorageCloseStat(src, &fd);
     return ret;
 }
@@ -12438,7 +12436,7 @@ qemuDomainMigratePrepareTunnel(virConnectPtr dconn,
 {
     virQEMUDriverPtr driver = dconn->privateData;
     virDomainDefPtr def = NULL;
-    char *origname = NULL;
+    VIR_AUTOFREE(char *) origname = NULL;
     qemuMigrationParamsPtr migParams = NULL;
     int ret = -1;
 
@@ -12473,7 +12471,6 @@ qemuDomainMigratePrepareTunnel(virConnectPtr dconn,
 
  cleanup:
     qemuMigrationParamsFree(migParams);
-    VIR_FREE(origname);
     virDomainDefFree(def);
     return ret;
 }
@@ -12495,7 +12492,7 @@ qemuDomainMigratePrepare2(virConnectPtr dconn,
 {
     virQEMUDriverPtr driver = dconn->privateData;
     virDomainDefPtr def = NULL;
-    char *origname = NULL;
+    VIR_AUTOFREE(char *) origname = NULL;
     qemuMigrationParamsPtr migParams = NULL;
     int ret = -1;
 
@@ -12540,7 +12537,6 @@ qemuDomainMigratePrepare2(virConnectPtr dconn,
 
  cleanup:
     qemuMigrationParamsFree(migParams);
-    VIR_FREE(origname);
     virDomainDefFree(def);
     return ret;
 }
@@ -12741,7 +12737,7 @@ qemuDomainMigratePrepare3(virConnectPtr dconn,
 {
     virQEMUDriverPtr driver = dconn->privateData;
     virDomainDefPtr def = NULL;
-    char *origname = NULL;
+    VIR_AUTOFREE(char *) origname = NULL;
     qemuMigrationParamsPtr migParams = NULL;
     int ret = -1;
 
@@ -12776,7 +12772,6 @@ qemuDomainMigratePrepare3(virConnectPtr dconn,
 
  cleanup:
     qemuMigrationParamsFree(migParams);
-    VIR_FREE(origname);
     virDomainDefFree(def);
     return ret;
 }
@@ -12802,7 +12797,7 @@ qemuDomainMigratePrepare3Params(virConnectPtr dconn,
     int nbdPort = 0;
     int nmigrate_disks;
     const char **migrate_disks = NULL;
-    char *origname = NULL;
+    VIR_AUTOFREE(char *) origname = NULL;
     qemuMigrationParamsPtr migParams = NULL;
     int ret = -1;
 
@@ -12865,7 +12860,6 @@ qemuDomainMigratePrepare3Params(virConnectPtr dconn,
  cleanup:
     qemuMigrationParamsFree(migParams);
     VIR_FREE(migrate_disks);
-    VIR_FREE(origname);
     virDomainDefFree(def);
     return ret;
 }
@@ -12885,7 +12879,7 @@ qemuDomainMigratePrepareTunnel3(virConnectPtr dconn,
 {
     virQEMUDriverPtr driver = dconn->privateData;
     virDomainDefPtr def = NULL;
-    char *origname = NULL;
+    VIR_AUTOFREE(char *) origname = NULL;
     qemuMigrationParamsPtr migParams = NULL;
     int ret = -1;
 
@@ -12914,7 +12908,6 @@ qemuDomainMigratePrepareTunnel3(virConnectPtr dconn,
 
  cleanup:
     qemuMigrationParamsFree(migParams);
-    VIR_FREE(origname);
     virDomainDefFree(def);
     return ret;
 }
@@ -12934,7 +12927,7 @@ qemuDomainMigratePrepareTunnel3Params(virConnectPtr dconn,
     virDomainDefPtr def = NULL;
     const char *dom_xml = NULL;
     const char *dname = NULL;
-    char *origname = NULL;
+    VIR_AUTOFREE(char *) origname = NULL;
     qemuMigrationParamsPtr migParams = NULL;
     int ret = -1;
 
@@ -12973,7 +12966,6 @@ qemuDomainMigratePrepareTunnel3Params(virConnectPtr dconn,
 
  cleanup:
     qemuMigrationParamsFree(migParams);
-    VIR_FREE(origname);
     virDomainDefFree(def);
     return ret;
 }
@@ -13295,7 +13287,7 @@ qemuNodeDeviceDetachFlags(virNodeDevicePtr dev,
     unsigned domain = 0, bus = 0, slot = 0, function = 0;
     int ret = -1;
     virNodeDeviceDefPtr def = NULL;
-    char *xml = NULL;
+    VIR_AUTOFREE(char *) xml = NULL;
     bool vfio = qemuHostdevHostSupportsPassthroughVFIO();
     virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
 
@@ -13345,7 +13337,6 @@ qemuNodeDeviceDetachFlags(virNodeDevicePtr dev,
  cleanup:
     virPCIDeviceFree(pci);
     virNodeDeviceDefFree(def);
-    VIR_FREE(xml);
     return ret;
 }
 
@@ -13363,7 +13354,7 @@ qemuNodeDeviceReAttach(virNodeDevicePtr dev)
     unsigned domain = 0, bus = 0, slot = 0, function = 0;
     int ret = -1;
     virNodeDeviceDefPtr def = NULL;
-    char *xml = NULL;
+    VIR_AUTOFREE(char *) xml = NULL;
     virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
 
     xml = virNodeDeviceGetXMLDesc(dev, 0);
@@ -13389,7 +13380,6 @@ qemuNodeDeviceReAttach(virNodeDevicePtr dev)
     virPCIDeviceFree(pci);
  cleanup:
     virNodeDeviceDefFree(def);
-    VIR_FREE(xml);
     return ret;
 }
 
@@ -13401,7 +13391,7 @@ qemuNodeDeviceReset(virNodeDevicePtr dev)
     unsigned domain = 0, bus = 0, slot = 0, function = 0;
     int ret = -1;
     virNodeDeviceDefPtr def = NULL;
-    char *xml = NULL;
+    VIR_AUTOFREE(char *) xml = NULL;
     virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
 
     xml = virNodeDeviceGetXMLDesc(dev, 0);
@@ -13427,7 +13417,6 @@ qemuNodeDeviceReset(virNodeDevicePtr dev)
     virPCIDeviceFree(pci);
  cleanup:
     virNodeDeviceDefFree(def);
-    VIR_FREE(xml);
     return ret;
 }
 
@@ -15108,7 +15097,6 @@ qemuDomainSnapshotDiskPrepareOne(virQEMUDriverPtr driver,
                                  qemuDomainAsyncJob asyncJob)
 {
     qemuDomainObjPrivatePtr priv = vm->privateData;
-    char *backingStoreStr;
     virDomainDiskDefPtr persistdisk;
     VIR_AUTOUNREF(virStorageSourcePtr) terminator = NULL;
     bool supportsCreate;
@@ -15154,13 +15142,13 @@ qemuDomainSnapshotDiskPrepareOne(virQEMUDriverPtr driver,
          * block commit still works */
         if (reuse) {
             if (supportsBacking) {
+                VIR_AUTOFREE(char *) backingStoreStr = NULL;
+
                 if (virStorageFileGetBackingStoreStr(dd->src, &backingStoreStr) < 0)
                     return -1;
                 if (backingStoreStr != NULL) {
                     if (virStorageIsRelative(backingStoreStr))
                         VIR_STEAL_PTR(dd->relPath, backingStoreStr);
-                    else
-                        VIR_FREE(backingStoreStr);
                 }
             }
         } else {
@@ -15607,7 +15595,7 @@ qemuDomainSnapshotCreateXML(virDomainPtr domain,
 {
     virQEMUDriverPtr driver = domain->conn->privateData;
     virDomainObjPtr vm = NULL;
-    char *xml = NULL;
+    VIR_AUTOFREE(char *) xml = NULL;
     virDomainMomentObjPtr snap = NULL;
     virDomainSnapshotPtr snapshot = NULL;
     virDomainMomentObjPtr current = NULL;
@@ -15895,7 +15883,6 @@ qemuDomainSnapshotCreateXML(virDomainPtr domain,
 
  cleanup:
     virDomainObjEndAPI(&vm);
-    VIR_FREE(xml);
     return snapshot;
 }
 
@@ -17694,7 +17681,7 @@ qemuDomainBlockJobSetSpeed(virDomainPtr dom,
     virDomainDiskDefPtr disk;
     int ret = -1;
     virDomainObjPtr vm;
-    char *device = NULL;
+    VIR_AUTOFREE(char *) device = NULL;
     unsigned long long speed = bandwidth;
 
     virCheckFlags(VIR_DOMAIN_BLOCK_JOB_SPEED_BANDWIDTH_BYTES, -1);
@@ -17739,7 +17726,6 @@ qemuDomainBlockJobSetSpeed(virDomainPtr dom,
     qemuDomainObjEndJob(driver, vm);
 
  cleanup:
-    VIR_FREE(device);
     virDomainObjEndAPI(&vm);
 
     return ret;
@@ -18819,7 +18805,7 @@ qemuDomainSetBlockIoTune(virDomainPtr dom,
     virDomainDefPtr def = NULL;
     virDomainDefPtr persistentDef = NULL;
     virDomainBlockIoTuneInfo info;
-    char *drivealias = NULL;
+    VIR_AUTOFREE(char *) drivealias = NULL;
     const char *qdevid = NULL;
     int ret = -1;
     size_t i;
@@ -19146,7 +19132,6 @@ qemuDomainSetBlockIoTune(virDomainPtr dom,
 
  cleanup:
     VIR_FREE(info.group_name);
-    VIR_FREE(drivealias);
     virDomainObjEndAPI(&vm);
     if (eventNparams)
         virTypedParamsFree(eventParams, eventNparams);
@@ -19167,7 +19152,7 @@ qemuDomainGetBlockIoTune(virDomainPtr dom,
     virDomainDefPtr def = NULL;
     virDomainDefPtr persistentDef = NULL;
     virDomainBlockIoTuneInfo reply = {0};
-    char *drivealias = NULL;
+    VIR_AUTOFREE(char *) drivealias = NULL;
     const char *qdevid = NULL;
     int ret = -1;
     int maxparams;
@@ -19304,7 +19289,6 @@ qemuDomainGetBlockIoTune(virDomainPtr dom,
 
  cleanup:
     VIR_FREE(reply.group_name);
-    VIR_FREE(drivealias);
     virDomainObjEndAPI(&vm);
     return ret;
 }
@@ -20928,12 +20912,10 @@ qemuDomainGetStatsBlockExportDisk(virDomainDiskDefPtr disk,
                                   bool blockdev)
 
 {
-    char *alias = NULL;
     virStorageSourcePtr n;
     const char *frontendalias;
     const char *backendalias;
     const char *backendstoragealias;
-    int ret = -1;
 
     /*
      * This helps to keep logs clean from error messages on getting stats
@@ -20950,6 +20932,8 @@ qemuDomainGetStatsBlockExportDisk(virDomainDiskDefPtr disk,
     }
 
     for (n = disk->src; virStorageSourceIsBacking(n); n = n->backingStore) {
+        VIR_AUTOFREE(char *) alias = NULL;
+
         if (blockdev) {
             frontendalias = QEMU_DOMAIN_DISK_PRIVATE(disk)->qomName;
             backendalias = n->nodeformat;
@@ -20958,7 +20942,7 @@ qemuDomainGetStatsBlockExportDisk(virDomainDiskDefPtr disk,
             /* alias may be NULL if the VM is not running */
             if (disk->info.alias &&
                 !(alias = qemuDomainStorageAlias(disk->info.alias, n->id)))
-                goto cleanup;
+                return -1;
 
             qemuDomainGetStatsOneBlockRefreshNamed(n, alias, stats, nodestats);
 
@@ -20968,37 +20952,32 @@ qemuDomainGetStatsBlockExportDisk(virDomainDiskDefPtr disk,
         }
 
         if (qemuDomainGetStatsBlockExportHeader(disk, n, *recordnr, params) < 0)
-            goto cleanup;
+            return -1;
 
         /* The following stats make sense only for the frontend device */
         if (n == disk->src) {
             if (qemuDomainGetStatsBlockExportFrontend(frontendalias, stats, *recordnr,
                                                       params) < 0)
-                goto cleanup;
+                return -1;
         }
 
         if (qemuDomainGetStatsOneBlock(driver, cfg, dom, params,
                                        backendalias, n, *recordnr,
                                        stats) < 0)
-            goto cleanup;
+            return -1;
 
         if (qemuDomainGetStatsBlockExportBackendStorage(backendstoragealias,
                                                         stats, *recordnr,
                                                         params) < 0)
-            goto cleanup;
+            return -1;
 
-        VIR_FREE(alias);
         (*recordnr)++;
 
         if (!visitBacking)
             break;
     }
 
-    ret = 0;
-
- cleanup:
-    VIR_FREE(alias);
-    return ret;
+    return 0;
 }
 
 
@@ -21714,12 +21693,12 @@ qemuDomainRenameCallback(virDomainObjPtr vm,
     virObjectEventPtr event_new = NULL;
     virObjectEventPtr event_old = NULL;
     int ret = -1;
-    char *new_dom_name = NULL;
-    char *old_dom_name = NULL;
-    char *new_dom_cfg_file = NULL;
-    char *old_dom_cfg_file = NULL;
-    char *new_dom_autostart_link = NULL;
-    char *old_dom_autostart_link = NULL;
+    VIR_AUTOFREE(char *) new_dom_name = NULL;
+    VIR_AUTOFREE(char *) old_dom_name = NULL;
+    VIR_AUTOFREE(char *) new_dom_cfg_file = NULL;
+    VIR_AUTOFREE(char *) old_dom_cfg_file = NULL;
+    VIR_AUTOFREE(char *) new_dom_autostart_link = NULL;
+    VIR_AUTOFREE(char *) old_dom_autostart_link = NULL;
 
     virCheckFlags(0, ret);
 
@@ -21791,12 +21770,6 @@ qemuDomainRenameCallback(virDomainObjPtr vm,
     ret = 0;
 
  cleanup:
-    VIR_FREE(old_dom_autostart_link);
-    VIR_FREE(new_dom_autostart_link);
-    VIR_FREE(old_dom_cfg_file);
-    VIR_FREE(new_dom_cfg_file);
-    VIR_FREE(old_dom_name);
-    VIR_FREE(new_dom_name);
     virObjectEventStateQueue(driver->domainEventState, event_old);
     virObjectEventStateQueue(driver->domainEventState, event_new);
     return ret;
@@ -21901,7 +21874,7 @@ qemuDomainGetGuestVcpusParams(virTypedParameterPtr *params,
     virBitmapPtr vcpus = NULL;
     virBitmapPtr online = NULL;
     virBitmapPtr offlinable = NULL;
-    char *tmp = NULL;
+    VIR_AUTOFREE(char *) tmp = NULL;
     size_t i;
     int ret = -1;
 
@@ -21930,7 +21903,6 @@ qemuDomainGetGuestVcpusParams(virTypedParameterPtr *params,
         goto cleanup; \
     if (virTypedParamsAddString(&par, &npar, &maxpar, #name, tmp) < 0) \
         goto cleanup; \
-    VIR_FREE(tmp)
 
     ADD_BITMAP(vcpus);
     ADD_BITMAP(online);
@@ -21944,7 +21916,6 @@ qemuDomainGetGuestVcpusParams(virTypedParameterPtr *params,
     ret = 0;
 
  cleanup:
-    VIR_FREE(tmp);
     virBitmapFree(vcpus);
     virBitmapFree(online);
     virBitmapFree(offlinable);
@@ -22172,7 +22143,7 @@ qemuDomainSetBlockThreshold(virDomainPtr dom,
     qemuDomainObjPrivatePtr priv;
     virDomainObjPtr vm = NULL;
     virStorageSourcePtr src;
-    char *nodename = NULL;
+    VIR_AUTOFREE(char *) nodename = NULL;
     int rc;
     int ret = -1;
 
@@ -22226,7 +22197,6 @@ qemuDomainSetBlockThreshold(virDomainPtr dom,
     qemuDomainObjEndJob(driver, vm);
 
  cleanup:
-    VIR_FREE(nodename);
     virDomainObjEndAPI(&vm);
     return ret;
 }
@@ -22400,7 +22370,7 @@ qemuDomainGetSEVMeasurement(virQEMUDriverPtr driver,
                             unsigned int flags)
 {
     int ret = -1;
-    char *tmp = NULL;
+    VIR_AUTOFREE(char *) tmp = NULL;
     int maxpar = 0;
 
     virCheckFlags(VIR_TYPED_PARAM_STRING_OKAY, -1);
@@ -22425,7 +22395,6 @@ qemuDomainGetSEVMeasurement(virQEMUDriverPtr driver,
     ret = 0;
 
  endjob:
-    VIR_FREE(tmp);
     qemuDomainObjEndJob(driver, vm);
     return ret;
 }
-- 
2.21.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[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