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

[libvirt] [PATCH] Prefer VIR_STRDUP over virAsprintf(&dst, "%s", str)



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                  |  2 +-
 src/conf/domain_audit.c                   |  2 +-
 src/libxl/libxl_driver.c                  | 30 ++++++++++++------------------
 src/nwfilter/nwfilter_ebiptables_driver.c |  2 +-
 src/phyp/phyp_driver.c                    |  4 +---
 src/storage/storage_backend_scsi.c        |  4 +---
 6 files changed, 17 insertions(+), 27 deletions(-)

diff --git a/daemon/libvirtd-config.c b/daemon/libvirtd-config.c
index 66dfb4a..d9357b7 100644
--- a/daemon/libvirtd-config.c
+++ b/daemon/libvirtd-config.c
@@ -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 */
diff --git a/src/conf/domain_audit.c b/src/conf/domain_audit.c
index fd3de5e..97e71f7 100644
--- a/src/conf/domain_audit.c
+++ b/src/conf/domain_audit.c
@@ -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;
         }
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index bed583b..3990354 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -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"),
diff --git a/src/nwfilter/nwfilter_ebiptables_driver.c b/src/nwfilter/nwfilter_ebiptables_driver.c
index c4fcde6..9a54de4 100644
--- a/src/nwfilter/nwfilter_ebiptables_driver.c
+++ b/src/nwfilter/nwfilter_ebiptables_driver.c
@@ -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 ",
diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c
index 70d3adb..2df082b 100644
--- a/src/phyp/phyp_driver.c
+++ b/src/phyp/phyp_driver.c
@@ -259,10 +259,8 @@ phypGetSystemType(virConnectPtr conn)
     char *ret = NULL;
     int exit_status = 0;
 
-    if (virAsprintf(&cmd, "lshmc -V") < 0) {
-        virReportOOMError();
+    if (VIR_STRDUP(cmd, "lshmc -V") < 0)
         return -1;
-    }
     ret = phypExec(session, cmd, &exit_status, conn);
 
     VIR_FREE(cmd);
diff --git a/src/storage/storage_backend_scsi.c b/src/storage/storage_backend_scsi.c
index bd6a2a9..4dad1eb 100644
--- a/src/storage/storage_backend_scsi.c
+++ b/src/storage/storage_backend_scsi.c
@@ -507,10 +507,8 @@ virStorageBackendSCSIFindLUs(virStoragePoolObjPtr pool,
 
     virFileWaitForDevices();
 
-    if (virAsprintf(&device_path, "/sys/bus/scsi/devices") < 0) {
-        virReportOOMError();
+    if (VIR_STRDUP(device_path, "/sys/bus/scsi/devices") < 0)
         goto out;
-    }
 
     devicedir = opendir(device_path);
 
-- 
1.8.2.1


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