]> xenbits.xensource.com Git - libvirt.git/commitdiff
Prefer VIR_STRDUP over virAsprintf(&dst, "%s", str)
authorMichal Privoznik <mprivozn@redhat.com>
Fri, 7 Jun 2013 13:20:35 +0000 (15:20 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 7 Jun 2013 15:45:53 +0000 (17:45 +0200)
There's no sense in using virAsprintf() just to duplicate a string.
We should use VIR_STRDUP which is designed just for that.

daemon/libvirtd-config.c
src/conf/domain_audit.c
src/libxl/libxl_driver.c
src/nwfilter/nwfilter_ebiptables_driver.c
src/phyp/phyp_driver.c
src/storage/storage_backend_scsi.c

index 66dfb4acafbb71cc685f5f64ab4fb35f03ac8127..d9357b7470b490e727942af2c60e90c1c6acd357 100644 (file)
@@ -283,7 +283,7 @@ daemonConfigNew(bool privileged ATTRIBUTE_UNUSED)
          * running in disconnected operation, and report a less
          * useful Avahi string
          */
-        ret = virAsprintf(&data->mdns_name, "Virtualization Host");
+        ret = VIR_STRDUP(data->mdns_name, "Virtualization Host");
     } else {
         char *tmp;
         /* Extract the host part of the potentially FQDN */
index fd3de5eeb695156269f173fea800e29b33774572..97e71f7934f811d66a94ff26d97aa7d9074cab70 100644 (file)
@@ -505,7 +505,7 @@ virDomainAuditRedirdev(virDomainObjPtr vm, virDomainRedirdevDefPtr redirdev,
 
     switch (redirdev->bus) {
     case VIR_DOMAIN_REDIRDEV_BUS_USB:
-        if (virAsprintf(&address, "USB redirdev") < 0) {
+        if (VIR_STRDUP_QUIET(address, "USB redirdev") < 0) {
             VIR_WARN("OOM while encoding audit message");
             goto cleanup;
         }
index bed583b093b47eed17193f7913d89c2bce3d49a4..3990354f818af5b21be781ec02fda698290ed1f8 100644 (file)
@@ -1191,29 +1191,23 @@ libxlStateInitialize(bool privileged,
     if (!(libxl_driver->domains = virDomainObjListNew()))
         goto error;
 
-    if (virAsprintf(&libxl_driver->configDir,
-                    "%s", LIBXL_CONFIG_DIR) == -1)
-        goto out_of_memory;
+    if (VIR_STRDUP(libxl_driver->configDir, LIBXL_CONFIG_DIR) < 0)
+        goto error;
 
-    if (virAsprintf(&libxl_driver->autostartDir,
-                    "%s", LIBXL_AUTOSTART_DIR) == -1)
-        goto out_of_memory;
+    if (VIR_STRDUP(libxl_driver->autostartDir, LIBXL_AUTOSTART_DIR) < 0)
+        goto error;
 
-    if (virAsprintf(&libxl_driver->logDir,
-                    "%s", LIBXL_LOG_DIR) == -1)
-        goto out_of_memory;
+    if (VIR_STRDUP(libxl_driver->logDir, LIBXL_LOG_DIR) < 0)
+        goto error;
 
-    if (virAsprintf(&libxl_driver->stateDir,
-                    "%s", LIBXL_STATE_DIR) == -1)
-        goto out_of_memory;
+    if (VIR_STRDUP(libxl_driver->stateDir, LIBXL_STATE_DIR) < 0)
+        goto error;
 
-    if (virAsprintf(&libxl_driver->libDir,
-                    "%s", LIBXL_LIB_DIR) == -1)
-        goto out_of_memory;
+    if (VIR_STRDUP(libxl_driver->libDir, LIBXL_LIB_DIR) < 0)
+        goto error;
 
-    if (virAsprintf(&libxl_driver->saveDir,
-                    "%s", LIBXL_SAVE_DIR) == -1)
-        goto out_of_memory;
+    if (VIR_STRDUP(libxl_driver->saveDir, LIBXL_SAVE_DIR) < 0)
+        goto error;
 
     if (virFileMakePath(libxl_driver->logDir) < 0) {
         VIR_ERROR(_("Failed to create log dir '%s': %s"),
index c4fcde697b1d60281ac38d84e79fa3d902176f0a..9a54de4208fac4ce28f4642f96114a8f2db24e15 100644 (file)
@@ -3008,7 +3008,7 @@ ebtablesCreateTmpSubChain(ebiptablesRuleInstPtr *inst,
         ignore_value(VIR_STRDUP(protostr, ""));
         break;
     case L2_PROTO_STP_IDX:
-        ignore_value(virAsprintf(&protostr, "-d " NWFILTER_MAC_BGA " "));
+        ignore_value(VIR_STRDUP(protostr, "-d " NWFILTER_MAC_BGA " "));
         break;
     default:
         ignore_value(virAsprintf(&protostr, "-p 0x%04x ",
index 70d3adbe65bc12b145e7d1698890d1327010f01d..cae3b59e8d4a7783547a81c35a3f0945407d975f 100644 (file)
@@ -255,17 +255,11 @@ phypGetSystemType(virConnectPtr conn)
 {
     ConnectionData *connection_data = conn->networkPrivateData;
     LIBSSH2_SESSION *session = connection_data->session;
-    char *cmd = NULL;
     char *ret = NULL;
     int exit_status = 0;
 
-    if (virAsprintf(&cmd, "lshmc -V") < 0) {
-        virReportOOMError();
-        return -1;
-    }
-    ret = phypExec(session, cmd, &exit_status, conn);
+    ret = phypExec(session, "lshmc -V", &exit_status, conn);
 
-    VIR_FREE(cmd);
     VIR_FREE(ret);
     return exit_status;
 }
index bd6a2a96a1a74781ced9c91c96aa07dc239da7f5..285c5cbf10c5bed31e7818996a5f7b267b894e67 100644 (file)
@@ -498,7 +498,7 @@ virStorageBackendSCSIFindLUs(virStoragePoolObjPtr pool,
 {
     int retval = 0;
     uint32_t bus, target, lun;
-    char *device_path = NULL;
+    const char *device_path = "/sys/bus/scsi/devices";
     DIR *devicedir = NULL;
     struct dirent *lun_dirent = NULL;
     char devicepattern[64];
@@ -507,18 +507,12 @@ virStorageBackendSCSIFindLUs(virStoragePoolObjPtr pool,
 
     virFileWaitForDevices();
 
-    if (virAsprintf(&device_path, "/sys/bus/scsi/devices") < 0) {
-        virReportOOMError();
-        goto out;
-    }
-
     devicedir = opendir(device_path);
 
     if (devicedir == NULL) {
         virReportSystemError(errno,
                              _("Failed to opendir path '%s'"), device_path);
-        retval = -1;
-        goto out;
+        return -1;
     }
 
     snprintf(devicepattern, sizeof(devicepattern), "%u:%%u:%%u:%%u\n", scanhost);
@@ -536,8 +530,6 @@ virStorageBackendSCSIFindLUs(virStoragePoolObjPtr pool,
 
     closedir(devicedir);
 
-out:
-    VIR_FREE(device_path);
     return retval;
 }