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

[libvirt] [PATCH 09/19] qemu_command: use VIR_AUTOFREE for variables used once



Remove the VIR_FREE's from the cleanup sections.

Signed-off-by: Ján Tomko <jtomko redhat com>
---
 src/qemu/qemu_command.c | 207 +++++++++++++---------------------------
 1 file changed, 66 insertions(+), 141 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index b5448a074f..fe06867a88 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -203,8 +203,8 @@ qemuBuildMasterKeyCommandLine(virCommandPtr cmd,
                               qemuDomainObjPrivatePtr priv)
 {
     int ret = -1;
-    char *alias = NULL;
-    char *path = NULL;
+    VIR_AUTOFREE(char *) alias = NULL;
+    VIR_AUTOFREE(char *) path = NULL;
     VIR_AUTOCLEAN(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 
     /* If the -object secret does not exist, then just return. This just
@@ -235,8 +235,6 @@ qemuBuildMasterKeyCommandLine(virCommandPtr cmd,
     ret = 0;
 
  cleanup:
-    VIR_FREE(alias);
-    VIR_FREE(path);
     return ret;
 }
 
@@ -301,7 +299,7 @@ qemuBuildDeviceAddressStr(virBufferPtr buf,
                           virQEMUCapsPtr qemuCaps)
 {
     int ret = -1;
-    char *devStr = NULL;
+    VIR_AUTOFREE(char *) devStr = NULL;
     const char *contAlias = NULL;
     bool contIsPHB = false;
     int contTargetIndex = 0;
@@ -401,7 +399,6 @@ qemuBuildDeviceAddressStr(virBufferPtr buf,
 
     ret = 0;
  cleanup:
-    VIR_FREE(devStr);
     return ret;
 }
 
@@ -703,7 +700,7 @@ qemuBuildSecretInfoProps(qemuDomainSecretInfoPtr secinfo,
                          virJSONValuePtr *propsret)
 {
     int ret = -1;
-    char *keyid = NULL;
+    VIR_AUTOFREE(char *) keyid = NULL;
 
     if (!(keyid = qemuDomainGetMasterKeyAlias()))
         return -1;
@@ -715,7 +712,6 @@ qemuBuildSecretInfoProps(qemuDomainSecretInfoPtr secinfo,
                                        "s:iv", secinfo->s.aes.iv,
                                        "s:format", "base64", NULL);
 
-    VIR_FREE(keyid);
     return ret;
 }
 
@@ -1518,13 +1514,12 @@ qemuCheckFips(void)
     bool ret = false;
 
     if (virFileExists("/proc/sys/crypto/fips_enabled")) {
-        char *buf = NULL;
+        VIR_AUTOFREE(char *) buf = NULL;
 
         if (virFileReadAll("/proc/sys/crypto/fips_enabled", 10, &buf) < 0)
             return ret;
         if (STREQ(buf, "1\n"))
             ret = true;
-        VIR_FREE(buf);
     }
 
     return ret;
@@ -1612,7 +1607,7 @@ static int
 qemuBuildDriveSourcePR(virBufferPtr buf,
                        virDomainDiskDefPtr disk)
 {
-    char *alias = NULL;
+    VIR_AUTOFREE(char *) alias = NULL;
     const char *defaultAlias = NULL;
 
     if (!disk->src->pr)
@@ -1625,7 +1620,6 @@ qemuBuildDriveSourcePR(virBufferPtr buf,
 
 
     virBufferAsprintf(buf, ",file.pr-manager=%s", alias ? alias : defaultAlias);
-    VIR_FREE(alias);
     return 0;
 }
 
@@ -1640,7 +1634,7 @@ qemuBuildDriveSourceStr(virDomainDiskDefPtr disk,
     qemuDomainSecretInfoPtr secinfo = NULL;
     qemuDomainSecretInfoPtr encinfo = NULL;
     VIR_AUTOPTR(virJSONValue) srcprops = NULL;
-    char *source = NULL;
+    VIR_AUTOFREE(char *) source = NULL;
     bool rawluks = false;
     int ret = -1;
 
@@ -1726,7 +1720,6 @@ qemuBuildDriveSourceStr(virDomainDiskDefPtr disk,
     ret = 0;
 
  cleanup:
-    VIR_FREE(source);
     return ret;
 }
 
@@ -1839,13 +1832,12 @@ qemuBuildDriveStr(virDomainDiskDefPtr disk,
         goto error;
 
     if (!qemuDiskBusNeedsDriveArg(disk->bus)) {
-        char *drivealias = qemuAliasDiskDriveFromDisk(disk);
+        VIR_AUTOFREE(char *) drivealias = qemuAliasDiskDriveFromDisk(disk);
         if (!drivealias)
             goto error;
 
         virBufferAddLit(&opt, "if=none");
         virBufferAsprintf(&opt, ",id=%s", drivealias);
-        VIR_FREE(drivealias);
     } else {
         int idx = virDiskNameToIndex(disk->dst);
 
@@ -2000,7 +1992,7 @@ qemuBuildDiskDeviceStr(const virDomainDef *def,
     VIR_AUTOCLEAN(virBuffer) opt = VIR_BUFFER_INITIALIZER;
     const char *bus = virDomainDiskQEMUBusTypeToString(disk->bus);
     const char *contAlias;
-    char *backendAlias = NULL;
+    VIR_AUTOFREE(char *) backendAlias = NULL;
     VIR_AUTOFREE(char *) scsiVPDDeviceId = NULL;
     int controllerModel;
 
@@ -2334,7 +2326,6 @@ qemuBuildDiskDeviceStr(const virDomainDef *def,
     return virBufferContentAndReset(&opt);
 
  error:
-    VIR_FREE(backendAlias);
     return NULL;
 }
 
@@ -2360,7 +2351,7 @@ static int
 qemuCommandAddZPCIDevice(virCommandPtr cmd,
                          virDomainDeviceInfoPtr dev)
 {
-    char *devstr = NULL;
+    VIR_AUTOFREE(char *) devstr = NULL;
 
     virCommandAddArg(cmd, "-device");
 
@@ -2369,7 +2360,6 @@ qemuCommandAddZPCIDevice(virCommandPtr cmd,
 
     virCommandAddArg(cmd, devstr);
 
-    VIR_FREE(devstr);
     return 0;
 }
 
@@ -2399,9 +2389,9 @@ qemuBuildFloppyCommandLineControllerOptions(virCommandPtr cmd,
     bool hasfloppy = false;
     unsigned int bootindex;
     char driveLetter;
-    char *backendAlias = NULL;
-    char *backendStr = NULL;
-    char *bootindexStr = NULL;
+    VIR_AUTOFREE(char *) backendAlias = NULL;
+    VIR_AUTOFREE(char *) backendStr = NULL;
+    VIR_AUTOFREE(char *) bootindexStr = NULL;
     size_t i;
     int ret = -1;
 
@@ -2471,9 +2461,6 @@ qemuBuildFloppyCommandLineControllerOptions(virCommandPtr cmd,
     ret = 0;
 
  cleanup:
-    VIR_FREE(backendAlias);
-    VIR_FREE(backendStr);
-    VIR_FREE(bootindexStr);
     return ret;
 }
 
@@ -2582,7 +2569,7 @@ qemuBuildDiskCommandLine(virCommandPtr cmd,
                          virQEMUCapsPtr qemuCaps,
                          unsigned int bootindex)
 {
-    char *optstr;
+    VIR_AUTOFREE(char *) optstr = NULL;
 
     if (qemuBuildDiskSourceCommandLine(cmd, disk, qemuCaps) < 0)
         return -1;
@@ -2599,7 +2586,6 @@ qemuBuildDiskCommandLine(virCommandPtr cmd,
                                                   qemuCaps)))
                 return -1;
             virCommandAddArg(cmd, optstr);
-            VIR_FREE(optstr);
         }
     }
 
@@ -3400,7 +3386,7 @@ qemuBuildMemoryBackendProps(virJSONValuePtr *backendProps,
     const long system_page_size = virGetSystemPageSizeKB();
     virDomainMemoryAccess memAccess = mem->access;
     size_t i;
-    char *memPath = NULL;
+    VIR_AUTOFREE(char *) memPath = NULL;
     bool prealloc = false;
     virBitmapPtr nodemask = NULL;
     int ret = -1;
@@ -3648,7 +3634,6 @@ qemuBuildMemoryBackendProps(virJSONValuePtr *backendProps,
         ret = -1;
 
  cleanup:
-    VIR_FREE(memPath);
     return ret;
 }
 
@@ -3661,7 +3646,7 @@ qemuBuildMemoryCellBackendStr(virDomainDefPtr def,
                               virBufferPtr buf)
 {
     VIR_AUTOPTR(virJSONValue) props = NULL;
-    char *alias = NULL;
+    VIR_AUTOFREE(char *) alias = NULL;
     int ret = -1;
     int rc;
     virDomainMemoryDef mem = { 0 };
@@ -3685,7 +3670,6 @@ qemuBuildMemoryCellBackendStr(virDomainDefPtr def,
     ret = rc;
 
  cleanup:
-    VIR_FREE(alias);
 
     return ret;
 }
@@ -3699,7 +3683,7 @@ qemuBuildMemoryDimmBackendStr(virBufferPtr buf,
                               qemuDomainObjPrivatePtr priv)
 {
     VIR_AUTOPTR(virJSONValue) props = NULL;
-    char *alias = NULL;
+    VIR_AUTOFREE(char *) alias = NULL;
     int ret = -1;
 
     if (!mem->info.alias) {
@@ -3721,7 +3705,6 @@ qemuBuildMemoryDimmBackendStr(virBufferPtr buf,
     ret = 0;
 
  cleanup:
-    VIR_FREE(alias);
 
     return ret;
 }
@@ -3995,7 +3978,6 @@ qemuBuildHostNetStr(virDomainNetDefPtr net,
     virDomainNetType netType = virDomainNetGetActualType(net);
     virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
     size_t i;
-    char *addr = NULL;
     char *ret = NULL;
 
     if (net->script && netType != VIR_DOMAIN_NET_TYPE_ETHERNET) {
@@ -4062,6 +4044,7 @@ qemuBuildHostNetStr(virDomainNetDefPtr net,
         virBufferAddLit(&buf, "user,");
         for (i = 0; i < net->guestIP.nips; i++) {
             const virNetDevIPAddr *ip = net->guestIP.ips[i];
+            VIR_AUTOFREE(char *) addr = NULL;
             const char *prefix = "";
 
             if (!(addr = virSocketAddrFormat(&ip->address)))
@@ -4076,7 +4059,6 @@ qemuBuildHostNetStr(virDomainNetDefPtr net,
             if (ip->prefix)
                 virBufferAsprintf(&buf, "/%u", ip->prefix);
             virBufferAddChar(&buf, ',');
-            VIR_FREE(addr);
         }
         break;
 
@@ -4127,7 +4109,6 @@ qemuBuildHostNetStr(virDomainNetDefPtr net,
     ret = virBufferContentAndReset(&buf);
  cleanup:
     virObjectUnref(cfg);
-    VIR_FREE(addr);
     return ret;
 }
 
@@ -4166,7 +4147,7 @@ qemuBuildWatchdogCommandLine(virCommandPtr cmd,
                              virQEMUCapsPtr qemuCaps)
 {
     virDomainWatchdogDefPtr watchdog = def->watchdog;
-    char *optstr;
+    VIR_AUTOFREE(char *) optstr = NULL;
     const char *action;
     int actualAction;
 
@@ -4183,7 +4164,6 @@ qemuBuildWatchdogCommandLine(virCommandPtr cmd,
         return -1;
 
     virCommandAddArg(cmd, optstr);
-    VIR_FREE(optstr);
 
     /* qemu doesn't have a 'dump' action; we tell qemu to 'pause', then
        libvirt listens for the watchdog event, and we perform the dump
@@ -4285,13 +4265,12 @@ qemuBuildNVRAMCommandLine(virCommandPtr cmd,
             return -1;
         }
 
-        char *optstr;
+        VIR_AUTOFREE(char *) optstr = NULL;
         virCommandAddArg(cmd, "-global");
         optstr = qemuBuildNVRAMDevStr(def->nvram);
         if (!optstr)
             return -1;
         virCommandAddArg(cmd, optstr);
-        VIR_FREE(optstr);
     } else {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                       _("nvram device is only supported for PPC64"));
@@ -4430,7 +4409,7 @@ qemuBuildInputCommandLine(virCommandPtr cmd,
 
     for (i = 0; i < def->ninputs; i++) {
         virDomainInputDefPtr input = def->inputs[i];
-        char *devstr = NULL;
+        VIR_AUTOFREE(char *) devstr = NULL;
 
         if (qemuCommandAddExtDevice(cmd, &input->info) < 0)
             return -1;
@@ -4442,8 +4421,6 @@ qemuBuildInputCommandLine(virCommandPtr cmd,
             virCommandAddArg(cmd, "-device");
             virCommandAddArg(cmd, devstr);
         }
-
-        VIR_FREE(devstr);
     }
 
     return 0;
@@ -4566,7 +4543,7 @@ qemuBuildSoundCommandLine(virCommandPtr cmd,
 
     for (i = 0; i < def->nsounds; i++) {
         virDomainSoundDefPtr sound = def->sounds[i];
-        char *str = NULL;
+        VIR_AUTOFREE(char *) str = NULL;
 
         /* Sadly pcspk device doesn't use -device syntax. Fortunately
          * we don't need to set any PCI address on it, so we don't
@@ -4582,7 +4559,6 @@ qemuBuildSoundCommandLine(virCommandPtr cmd,
                 return -1;
 
             virCommandAddArg(cmd, str);
-            VIR_FREE(str);
             if (sound->model == VIR_DOMAIN_SOUND_MODEL_ICH6 ||
                 sound->model == VIR_DOMAIN_SOUND_MODEL_ICH9) {
                 char *codecstr = NULL;
@@ -4808,7 +4784,7 @@ qemuBuildVideoCommandLine(virCommandPtr cmd,
     size_t i;
 
     for (i = 0; i < def->nvideos; i++) {
-        char *str = NULL;
+        VIR_AUTOFREE(char *) str = NULL;
         virDomainVideoDefPtr video = def->videos[i];
 
         if (video->type == VIR_DOMAIN_VIDEO_TYPE_NONE)
@@ -4827,7 +4803,6 @@ qemuBuildVideoCommandLine(virCommandPtr cmd,
                     return -1;
 
                 virCommandAddArg(cmd, str);
-                VIR_FREE(str);
             } else {
                 if (qemuBuildVgaVideoCommand(cmd, video, qemuCaps) < 0)
                     return -1;
@@ -4842,7 +4817,6 @@ qemuBuildVideoCommandLine(virCommandPtr cmd,
                 return -1;
 
             virCommandAddArg(cmd, str);
-            VIR_FREE(str);
         }
     }
 
@@ -4854,7 +4828,7 @@ int
 qemuOpenPCIConfig(virDomainHostdevDefPtr dev)
 {
     virDomainHostdevSubsysPCIPtr pcisrc = &dev->source.subsys.u.pci;
-    char *path = NULL;
+    VIR_AUTOFREE(char *) path = NULL;
     int configfd = -1;
 
     if (virAsprintf(&path, "/sys/bus/pci/devices/%04x:%02x:%02x.%01x/config",
@@ -4867,8 +4841,6 @@ qemuOpenPCIConfig(virDomainHostdevDefPtr dev)
     if (configfd < 0)
         virReportSystemError(errno, _("Failed opening %s"), path);
 
-    VIR_FREE(path);
-
     return configfd;
 }
 
@@ -5011,13 +4983,12 @@ qemuBuildHubCommandLine(virCommandPtr cmd,
 
     for (i = 0; i < def->nhubs; i++) {
         virDomainHubDefPtr hub = def->hubs[i];
-        char *optstr;
+        VIR_AUTOFREE(char *) optstr = NULL;
 
         virCommandAddArg(cmd, "-device");
         if (!(optstr = qemuBuildHubDevStr(def, hub, qemuCaps)))
             return -1;
         virCommandAddArg(cmd, optstr);
-        VIR_FREE(optstr);
     }
 
     return 0;
@@ -5043,7 +5014,7 @@ qemuBuildSCSIiSCSIHostdevDrvStr(virDomainHostdevDefPtr dev,
 {
     char *ret = NULL;
     VIR_AUTOCLEAN(virBuffer) buf = VIR_BUFFER_INITIALIZER;
-    char *netsource = NULL;
+    VIR_AUTOFREE(char *) netsource = NULL;
     VIR_AUTOPTR(virJSONValue) srcprops = NULL;
     virDomainHostdevSubsysSCSIPtr scsisrc = &dev->source.subsys.u.scsi;
     virDomainHostdevSubsysSCSIiSCSIPtr iscsisrc = &scsisrc->u.iscsi;
@@ -5072,7 +5043,6 @@ qemuBuildSCSIiSCSIHostdevDrvStr(virDomainHostdevDefPtr dev,
     ret = virBufferContentAndReset(&buf);
 
  cleanup:
-    VIR_FREE(netsource);
     return ret;
 }
 
@@ -5118,8 +5088,8 @@ qemuBuildSCSIHostdevDrvStr(virDomainHostdevDefPtr dev,
                            virQEMUCapsPtr qemuCaps)
 {
     VIR_AUTOCLEAN(virBuffer) buf = VIR_BUFFER_INITIALIZER;
-    char *source = NULL;
-    char *drivealias = NULL;
+    VIR_AUTOFREE(char *) source = NULL;
+    VIR_AUTOFREE(char *) drivealias = NULL;
     virDomainHostdevSubsysSCSIPtr scsisrc = &dev->source.subsys.u.scsi;
 
     if (scsisrc->protocol == VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISCSI) {
@@ -5131,12 +5101,10 @@ qemuBuildSCSIHostdevDrvStr(virDomainHostdevDefPtr dev,
             goto error;
         virBufferAsprintf(&buf, "file=/dev/%s,if=none,format=raw", source);
     }
-    VIR_FREE(source);
 
     if (!(drivealias = qemuAliasFromHostdev(dev)))
         goto error;
     virBufferAsprintf(&buf, ",id=%s", drivealias);
-    VIR_FREE(drivealias);
 
     if (dev->readonly)
         virBufferAddLit(&buf, ",readonly=on");
@@ -5155,7 +5123,7 @@ qemuBuildSCSIHostdevDevStr(const virDomainDef *def,
 {
     VIR_AUTOCLEAN(virBuffer) buf = VIR_BUFFER_INITIALIZER;
     int model = -1;
-    char *driveAlias;
+    VIR_AUTOFREE(char *) driveAlias = NULL;
     const char *contAlias;
 
     model = qemuDomainFindSCSIControllerModel(def, dev->info);
@@ -5200,7 +5168,6 @@ qemuBuildSCSIHostdevDevStr(const virDomainDef *def,
     if (!(driveAlias = qemuAliasFromHostdev(dev)))
         goto error;
     virBufferAsprintf(&buf, ",drive=%s,id=%s", driveAlias, dev->info->alias);
-    VIR_FREE(driveAlias);
 
     if (dev->info->bootIndex)
         virBufferAsprintf(&buf, ",bootindex=%u", dev->info->bootIndex);
@@ -5222,7 +5189,8 @@ qemuBuildChrChardevFileStr(virLogManagerPtr logManager,
                            const char *appendarg, int appendval)
 {
     if (logManager) {
-        char *fdset, *fdpath;
+        VIR_AUTOFREE(char *) fdset = NULL;
+        VIR_AUTOFREE(char *) fdpath = NULL;
         int flags = 0;
         int logfd;
 
@@ -5245,13 +5213,11 @@ qemuBuildChrChardevFileStr(virLogManagerPtr logManager,
 
         virCommandAddArg(cmd, "-add-fd");
         virCommandAddArg(cmd, fdset);
-        VIR_FREE(fdset);
 
         if (!(fdpath = qemuVirCommandGetDevSet(cmd, logfd)))
             return -1;
 
         virBufferAsprintf(buf, ",%s=%s,%s=on", filearg, fdpath, appendarg);
-        VIR_FREE(fdpath);
     } else {
         virBufferAsprintf(buf, ",%s=", filearg);
         virQEMUBuildBufferEscapeComma(buf, fileval);
@@ -5356,7 +5322,7 @@ qemuBuildChrChardevStr(virLogManagerPtr logManager,
     qemuDomainChrSourcePrivatePtr chrSourcePriv = QEMU_DOMAIN_CHR_SOURCE_PRIVATE(dev);
     VIR_AUTOCLEAN(virBuffer) buf = VIR_BUFFER_INITIALIZER;
     bool telnet;
-    char *charAlias = NULL;
+    VIR_AUTOFREE(char *) charAlias = NULL;
     char *ret = NULL;
 
     if (!(charAlias = qemuAliasChardevFromDevAlias(alias)))
@@ -5447,7 +5413,7 @@ qemuBuildChrChardevStr(virLogManagerPtr logManager,
         qemuBuildChrChardevReconnectStr(&buf, &dev->data.tcp.reconnect);
 
         if (dev->data.tcp.haveTLS == VIR_TRISTATE_BOOL_YES) {
-            char *objalias = NULL;
+            VIR_AUTOFREE(char *) objalias = NULL;
             const char *tlsCertEncSecAlias = NULL;
 
             /* Add the secret object first if necessary. The
@@ -5470,12 +5436,10 @@ qemuBuildChrChardevStr(virLogManagerPtr logManager,
                                             cfg->chardevTLSx509verify,
                                             tlsCertEncSecAlias,
                                             objalias, qemuCaps) < 0) {
-                VIR_FREE(objalias);
                 goto cleanup;
             }
 
             virBufferAsprintf(&buf, ",tls-creds=%s", objalias);
-            VIR_FREE(objalias);
         }
         break;
 
@@ -5544,7 +5508,6 @@ qemuBuildChrChardevStr(virLogManagerPtr logManager,
 
     ret = virBufferContentAndReset(&buf);
  cleanup:
-    VIR_FREE(charAlias);
     return ret;
 }
 
@@ -5556,7 +5519,7 @@ qemuBuildHostdevMediatedDevStr(const virDomainDef *def,
     VIR_AUTOCLEAN(virBuffer) buf = VIR_BUFFER_INITIALIZER;
     virDomainHostdevSubsysMediatedDevPtr mdevsrc = &dev->source.subsys.u.mdev;
     char *ret = NULL;
-    char *mdevPath = NULL;
+    VIR_AUTOFREE(char *) mdevPath = NULL;
     const char *dev_str = NULL;
 
     if (!(mdevPath = virMediatedDeviceGetSysfsPath(mdevsrc->uuidstr)))
@@ -5583,7 +5546,6 @@ qemuBuildHostdevMediatedDevStr(const virDomainDef *def,
     ret = virBufferContentAndReset(&buf);
 
  cleanup:
-    VIR_FREE(mdevPath);
     return ret;
 }
 
@@ -5598,7 +5560,7 @@ qemuBuildHostdevCommandLine(virCommandPtr cmd,
     for (i = 0; i < def->nhostdevs; i++) {
         virDomainHostdevDefPtr hostdev = def->hostdevs[i];
         virDomainHostdevSubsysPtr subsys = &hostdev->source.subsys;
-        char *devstr;
+        VIR_AUTOFREE(char *) devstr = NULL;
 
         if (hostdev->info->bootIndex) {
             if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS ||
@@ -5621,7 +5583,6 @@ qemuBuildHostdevCommandLine(virCommandPtr cmd,
                   qemuBuildUSBHostdevDevStr(def, hostdev, qemuCaps)))
                 return -1;
             virCommandAddArg(cmd, devstr);
-            VIR_FREE(devstr);
         }
 
         /* PCI */
@@ -5638,7 +5599,7 @@ qemuBuildHostdevCommandLine(virCommandPtr cmd,
                 }
             }
 
-            char *configfd_name = NULL;
+            VIR_AUTOFREE(char *) configfd_name = NULL;
             unsigned int bootIndex = hostdev->info->bootIndex;
 
             /* bootNet will be non-0 if boot order was set and no other
@@ -5668,18 +5629,16 @@ qemuBuildHostdevCommandLine(virCommandPtr cmd,
             virCommandAddArg(cmd, "-device");
             devstr = qemuBuildPCIHostdevDevStr(def, hostdev, bootIndex,
                                                configfd_name, qemuCaps);
-            VIR_FREE(configfd_name);
             if (!devstr)
                 return -1;
             virCommandAddArg(cmd, devstr);
-            VIR_FREE(devstr);
         }
 
         /* SCSI */
         if (virHostdevIsSCSIDevice(hostdev)) {
             virDomainHostdevSubsysSCSIPtr scsisrc =
                 &hostdev->source.subsys.u.scsi;
-            char *drvstr;
+            VIR_AUTOFREE(char *) drvstr = NULL;
 
             if (scsisrc->protocol == VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISCSI) {
                 virDomainHostdevSubsysSCSIiSCSIPtr iscsisrc =
@@ -5697,13 +5656,11 @@ qemuBuildHostdevCommandLine(virCommandPtr cmd,
             if (!(drvstr = qemuBuildSCSIHostdevDrvStr(hostdev, qemuCaps)))
                 return -1;
             virCommandAddArg(cmd, drvstr);
-            VIR_FREE(drvstr);
 
             virCommandAddArg(cmd, "-device");
             if (!(devstr = qemuBuildSCSIHostdevDevStr(def, hostdev)))
                 return -1;
             virCommandAddArg(cmd, devstr);
-            VIR_FREE(devstr);
         }
 
         /* SCSI_host */
@@ -5711,7 +5668,7 @@ qemuBuildHostdevCommandLine(virCommandPtr cmd,
             subsys->type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST) {
             if (hostdev->source.subsys.u.scsi_host.protocol ==
                 VIR_DOMAIN_HOSTDEV_SUBSYS_SCSI_HOST_PROTOCOL_TYPE_VHOST) {
-                char *vhostfdName = NULL;
+                VIR_AUTOFREE(char *) vhostfdName = NULL;
                 int vhostfd = -1;
 
                 if (virSCSIVHostOpenVhostSCSI(&vhostfd) < 0)
@@ -5729,14 +5686,10 @@ qemuBuildHostdevCommandLine(virCommandPtr cmd,
                 if (!(devstr = qemuBuildSCSIVHostHostdevDevStr(def,
                                                                hostdev,
                                                                qemuCaps,
-                                                               vhostfdName))) {
-                    VIR_FREE(vhostfdName);
+                                                               vhostfdName)))
                     return -1;
-                }
-                virCommandAddArg(cmd, devstr);
 
-                VIR_FREE(vhostfdName);
-                VIR_FREE(devstr);
+                virCommandAddArg(cmd, devstr);
             }
         }
 
@@ -5782,7 +5735,6 @@ qemuBuildHostdevCommandLine(virCommandPtr cmd,
                   qemuBuildHostdevMediatedDevStr(def, hostdev, qemuCaps)))
                 return -1;
             virCommandAddArg(cmd, devstr);
-            VIR_FREE(devstr);
         }
     }
 
@@ -5798,7 +5750,7 @@ qemuBuildMonitorCommandLine(virLogManagerPtr logManager,
                             virDomainDefPtr def,
                             qemuDomainObjPrivatePtr priv)
 {
-    char *chrdev;
+    VIR_AUTOFREE(char *) chrdev = NULL;
     unsigned int cdevflags = QEMU_BUILD_CHARDEV_TCP_NOWAIT |
         QEMU_BUILD_CHARDEV_UNIX_FD_PASS;
     if (priv->chardevStdioLogd)
@@ -5814,7 +5766,6 @@ qemuBuildMonitorCommandLine(virLogManagerPtr logManager,
         return -1;
     virCommandAddArg(cmd, "-chardev");
     virCommandAddArg(cmd, chrdev);
-    VIR_FREE(chrdev);
 
     virCommandAddArg(cmd, "-mon");
     virCommandAddArg(cmd, "chardev=charmonitor,id=monitor,mode=control");
@@ -5963,8 +5914,8 @@ qemuBuildRNGBackendProps(virDomainRNGDefPtr rng,
                          virQEMUCapsPtr qemuCaps,
                          virJSONValuePtr *props)
 {
-    char *objAlias = NULL;
-    char *charBackendAlias = NULL;
+    VIR_AUTOFREE(char *) objAlias = NULL;
+    VIR_AUTOFREE(char *) charBackendAlias = NULL;
     int ret = -1;
 
     if (virAsprintf(&objAlias, "obj%s", rng->info.alias) < 0)
@@ -6013,8 +5964,6 @@ qemuBuildRNGBackendProps(virDomainRNGDefPtr rng,
     ret = 0;
 
  cleanup:
-    VIR_FREE(objAlias);
-    VIR_FREE(charBackendAlias);
     return ret;
 }
 
@@ -6585,13 +6534,12 @@ qemuBuildClockCommandLine(virCommandPtr cmd,
                           virQEMUCapsPtr qemuCaps)
 {
     size_t i;
-    char *rtcopt;
+    VIR_AUTOFREE(char *) rtcopt = NULL;
 
     virCommandAddArg(cmd, "-rtc");
     if (!(rtcopt = qemuBuildClockArgStr(&def->clock)))
         return -1;
     virCommandAddArg(cmd, rtcopt);
-    VIR_FREE(rtcopt);
 
     if (def->clock.offset == VIR_DOMAIN_CLOCK_OFFSET_TIMEZONE &&
         def->clock.data.timezone) {
@@ -6747,7 +6695,7 @@ qemuBuildBootCommandLine(virCommandPtr cmd,
                          virQEMUCapsPtr qemuCaps)
 {
     VIR_AUTOCLEAN(virBuffer) boot_buf = VIR_BUFFER_INITIALIZER;
-    char *boot_opts_str = NULL;
+    VIR_AUTOFREE(char *) boot_opts_str = NULL;
 
     if (def->os.bootmenu) {
         if (def->os.bootmenu == VIR_TRISTATE_BOOL_YES)
@@ -6814,7 +6762,6 @@ qemuBuildBootCommandLine(virCommandPtr cmd,
     return 0;
 
  error:
-    VIR_FREE(boot_opts_str);
     return -1;
 }
 
@@ -7047,7 +6994,8 @@ qemuBuildCpuCommandLine(virCommandPtr cmd,
                         virQEMUCapsPtr qemuCaps)
 {
     virArch hostarch = virArchFromHost();
-    char *cpu = NULL, *cpu_flags = NULL;
+    VIR_AUTOFREE(char *) cpu = NULL;
+    VIR_AUTOFREE(char *) cpu_flags = NULL;
     int ret = -1;
     VIR_AUTOCLEAN(virBuffer) cpu_buf = VIR_BUFFER_INITIALIZER;
     VIR_AUTOCLEAN(virBuffer) buf = VIR_BUFFER_INITIALIZER;
@@ -7259,8 +7207,6 @@ qemuBuildCpuCommandLine(virCommandPtr cmd,
     ret = 0;
 
  cleanup:
-    VIR_FREE(cpu);
-    VIR_FREE(cpu_flags);
     return ret;
 }
 
@@ -7665,7 +7611,7 @@ static int
 qemuBuildSmpCommandLine(virCommandPtr cmd,
                         virDomainDefPtr def)
 {
-    char *smp;
+    char *smp = NULL;
     VIR_AUTOCLEAN(virBuffer) buf = VIR_BUFFER_INITIALIZER;
     unsigned int maxvcpus = virDomainDefGetVcpusMax(def);
     unsigned int nvcpus = 0;
@@ -7716,7 +7662,7 @@ qemuBuildMemPathStr(virQEMUDriverConfigPtr cfg,
                     qemuDomainObjPrivatePtr priv)
 {
     const long system_page_size = virGetSystemPageSizeKB();
-    char *mem_path = NULL;
+    VIR_AUTOFREE(char *) mem_path = NULL;
 
     /* There are two cases where we want to put -mem-path onto
      * the command line: First one is when there are no guest
@@ -7743,7 +7689,6 @@ qemuBuildMemPathStr(virQEMUDriverConfigPtr cfg,
     }
 
     virCommandAddArgList(cmd, "-mem-path", mem_path, NULL);
-    VIR_FREE(mem_path);
 
     return 0;
 }
@@ -8602,9 +8547,9 @@ qemuBuildInterfaceCommandLine(virQEMUDriverPtr driver,
                               int **nicindexes)
 {
     int ret = -1;
-    char *nic = NULL;
-    char *host = NULL;
-    char *chardev = NULL;
+    VIR_AUTOFREE(char *) nic = NULL;
+    VIR_AUTOFREE(char *) host = NULL;
+    VIR_AUTOFREE(char *) chardev = NULL;
     int *tapfd = NULL;
     size_t tapfdSize = 0;
     int *vhostfd = NULL;
@@ -8918,9 +8863,6 @@ qemuBuildInterfaceCommandLine(virQEMUDriverPtr driver,
     VIR_FREE(tapfdName);
     VIR_FREE(vhostfd);
     VIR_FREE(tapfd);
-    VIR_FREE(chardev);
-    VIR_FREE(host);
-    VIR_FREE(nic);
     return ret;
 }
 
@@ -9031,7 +8973,7 @@ qemuBuildSmartcardCommandLine(virLogManagerPtr logManager,
 {
     size_t i;
     virDomainSmartcardDefPtr smartcard;
-    char *devstr;
+    VIR_AUTOFREE(char *) devstr = NULL;
     VIR_AUTOCLEAN(virBuffer) opt = VIR_BUFFER_INITIALIZER;
     const char *database;
     const char *contAlias = NULL;
@@ -9109,7 +9051,6 @@ qemuBuildSmartcardCommandLine(virLogManagerPtr logManager,
         }
         virCommandAddArg(cmd, "-chardev");
         virCommandAddArg(cmd, devstr);
-        VIR_FREE(devstr);
 
         virBufferAsprintf(&opt, "ccid-card-passthru,chardev=char%s",
                           smartcard->info.alias);
@@ -9231,8 +9172,8 @@ qemuBuildShmemDevStr(virDomainDefPtr def,
 virJSONValuePtr
 qemuBuildShmemBackendMemProps(virDomainShmemDefPtr shmem)
 {
-    char *mem_alias = NULL;
-    char *mem_path = NULL;
+    VIR_AUTOFREE(char *) mem_alias = NULL;
+    VIR_AUTOFREE(char *) mem_path = NULL;
     virJSONValuePtr ret = NULL;
 
     if (virAsprintf(&mem_path, "/dev/shm/%s", shmem->name) < 0)
@@ -9248,8 +9189,6 @@ qemuBuildShmemBackendMemProps(virDomainShmemDefPtr shmem)
                                  NULL);
 
  cleanup:
-    VIR_FREE(mem_alias);
-    VIR_FREE(mem_path);
     return ret;
 }
 
@@ -9387,13 +9326,12 @@ qemuBuildChrDeviceCommandLine(virCommandPtr cmd,
                               virDomainChrDefPtr chr,
                               virQEMUCapsPtr qemuCaps)
 {
-    char *devstr = NULL;
+    VIR_AUTOFREE(char *) devstr = NULL;
 
     if (qemuBuildChrDeviceStr(&devstr, def, chr, qemuCaps) < 0)
         return -1;
 
     virCommandAddArgList(cmd, "-device", devstr, NULL);
-    VIR_FREE(devstr);
     return 0;
 }
 
@@ -9461,7 +9399,7 @@ qemuBuildSerialCommandLine(virLogManagerPtr logManager,
 
     for (i = 0; i < def->nserials; i++) {
         virDomainChrDefPtr serial = def->serials[i];
-        char *devstr;
+        VIR_AUTOFREE(char *) devstr = NULL;
 
         if (serial->source->type == VIR_DOMAIN_CHR_TYPE_SPICEPORT && !havespice)
             continue;
@@ -9474,7 +9412,6 @@ qemuBuildSerialCommandLine(virLogManagerPtr logManager,
             return -1;
         virCommandAddArg(cmd, "-chardev");
         virCommandAddArg(cmd, devstr);
-        VIR_FREE(devstr);
 
         /* If the device is not a platform device, build the devstr */
         if (!qemuChrIsPlatformDevice(def, serial)) {
@@ -9518,7 +9455,7 @@ qemuBuildParallelsCommandLine(virLogManagerPtr logManager,
 
     for (i = 0; i < def->nparallels; i++) {
         virDomainChrDefPtr parallel = def->parallels[i];
-        char *devstr;
+        VIR_AUTOFREE(char *) devstr = NULL;
 
         if (!(devstr = qemuBuildChrChardevStr(logManager, secManager,
                                               cmd, cfg, def,
@@ -9528,7 +9465,6 @@ qemuBuildParallelsCommandLine(virLogManagerPtr logManager,
             return -1;
         virCommandAddArg(cmd, "-chardev");
         virCommandAddArg(cmd, devstr);
-        VIR_FREE(devstr);
 
         if (qemuBuildChrDeviceCommandLine(cmd, def, parallel,
                                           qemuCaps) < 0)
@@ -9947,9 +9883,9 @@ qemuBuildTPMBackendStr(const virDomainDef *def,
 {
     const virDomainTPMDef *tpm = def->tpm;
     VIR_AUTOCLEAN(virBuffer) buf = VIR_BUFFER_INITIALIZER;
-    char *cancel_path = NULL;
-    char *devset = NULL;
-    char *cancelset = NULL;
+    VIR_AUTOFREE(char *) cancel_path = NULL;
+    VIR_AUTOFREE(char *) devset = NULL;
+    VIR_AUTOFREE(char *) cancelset = NULL;
     const char *tpmdev;
 
     *tpmfd = -1;
@@ -9980,10 +9916,6 @@ qemuBuildTPMBackendStr(const virDomainDef *def,
         virBufferAddLit(&buf, ",cancel-path=");
         virQEMUBuildBufferEscapeComma(&buf, cancelset);
 
-        VIR_FREE(devset);
-        VIR_FREE(cancelset);
-        VIR_FREE(cancel_path);
-
         break;
     case VIR_DOMAIN_TPM_TYPE_EMULATOR:
         virBufferAddLit(&buf, ",chardev=chrtpm");
@@ -10003,8 +9935,6 @@ qemuBuildTPMBackendStr(const virDomainDef *def,
     return virBufferContentAndReset(&buf);
 
  error:
-    VIR_FREE(devset);
-    VIR_FREE(cancel_path);
     return NULL;
 }
 
@@ -10015,7 +9945,7 @@ qemuBuildTPMCommandLine(virCommandPtr cmd,
                         virQEMUCapsPtr qemuCaps)
 {
     char *optstr;
-    char *chardev = NULL;
+    VIR_AUTOFREE(char *) chardev = NULL;
     int tpmfd = -1;
     int cancelfd = -1;
     char *fdset;
@@ -10031,10 +9961,8 @@ qemuBuildTPMCommandLine(virCommandPtr cmd,
     virCommandAddArgList(cmd, "-tpmdev", optstr, NULL);
     VIR_FREE(optstr);
 
-    if (chardev) {
+    if (chardev)
         virCommandAddArgList(cmd, "-chardev", chardev, NULL);
-        VIR_FREE(chardev);
-    }
 
     if (tpmfd >= 0) {
         fdset = qemuVirCommandGetFDSet(cmd, tpmfd);
@@ -10252,7 +10180,7 @@ qemuBuildPRManagerInfoPropsInternal(const char *alias,
 virJSONValuePtr
 qemuBuildPRManagedManagerInfoProps(qemuDomainObjPrivatePtr priv)
 {
-    char *path = NULL;
+    VIR_AUTOFREE(char *) path = NULL;
     virJSONValuePtr ret = NULL;
 
     if (!(path = qemuDomainGetManagedPRSocketPath(priv)))
@@ -10261,7 +10189,6 @@ qemuBuildPRManagedManagerInfoProps(qemuDomainObjPrivatePtr priv)
     ret = qemuBuildPRManagerInfoPropsInternal(qemuDomainGetManagedPRAlias(),
                                               path);
 
-    VIR_FREE(path);
     return ret;
 }
 
@@ -10463,7 +10390,7 @@ qemuBuildVsockCommandLine(virCommandPtr cmd,
                           virQEMUCapsPtr qemuCaps)
 {
     qemuDomainVsockPrivatePtr priv = (qemuDomainVsockPrivatePtr)vsock->privateData;
-    char *devstr = NULL;
+    VIR_AUTOFREE(char *) devstr = NULL;
     int ret = -1;
 
     if (!(devstr = qemuBuildVsockDevStr(def, vsock, qemuCaps, "")))
@@ -10479,7 +10406,6 @@ qemuBuildVsockCommandLine(virCommandPtr cmd,
 
     ret = 0;
  cleanup:
-    VIR_FREE(devstr);
     return ret;
 }
 
@@ -10845,7 +10771,7 @@ qemuBuildChannelChrDeviceStr(char **deviceStr,
                              virDomainChrDefPtr chr)
 {
     int ret = -1;
-    char *addr = NULL;
+    VIR_AUTOFREE(char *) addr = NULL;
     int port;
 
     switch ((virDomainChrChannelTargetType)chr->targetType) {
@@ -10875,7 +10801,6 @@ qemuBuildChannelChrDeviceStr(char **deviceStr,
 
     ret = 0;
  cleanup:
-    VIR_FREE(addr);
     return ret;
 }
 
-- 
2.19.2


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