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

[libvirt] [PATCH v2 18/37] Adapt to VIR_STRDUP in src/qemu/*



This requires some changes to libvirt,h,in and remote driver as well for
const correctness sake.
---
 include/libvirt/libvirt.h.in |  10 +-
 src/qemu/qemu_capabilities.c |  37 +++---
 src/qemu/qemu_cgroup.c       |   3 +-
 src/qemu/qemu_command.c      | 281 +++++++++++++++++--------------------------
 src/qemu/qemu_conf.c         |  32 +++--
 src/qemu/qemu_domain.c       |  16 +--
 src/qemu/qemu_driver.c       |  91 +++++++-------
 src/qemu/qemu_hotplug.c      |   8 +-
 src/qemu/qemu_migration.c    |  14 +--
 src/qemu/qemu_monitor_json.c |  40 +++---
 src/qemu/qemu_monitor_text.c |   9 +-
 src/qemu/qemu_process.c      |  56 +++++----
 src/remote/remote_driver.c   |   2 +-
 13 files changed, 258 insertions(+), 341 deletions(-)

diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index 693b834..9a8090d 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -1294,7 +1294,7 @@ typedef enum {
 
 struct _virConnectCredential {
     int type; /* One of virConnectCredentialType constants */
-    const char *prompt; /* Prompt to show to user */
+    char *prompt; /* Prompt to show to user */
     const char *challenge; /* Additional challenge to show */
     const char *defresult; /* Optional default result */
     char *result; /* Result to be filled with user response (or defresult) */
@@ -4504,8 +4504,8 @@ typedef enum {
  */
 struct _virDomainEventGraphicsAddress {
     int family;               /* Address family, virDomainEventGraphicsAddressType */
-    const char *node;         /* Address of node (eg IP address, or UNIX path) */
-    const char *service;      /* Service name/number (eg TCP port, or NULL) */
+    char *node;               /* Address of node (eg IP address, or UNIX path) */
+    char *service;            /* Service name/number (eg TCP port, or NULL) */
 };
 typedef struct _virDomainEventGraphicsAddress virDomainEventGraphicsAddress;
 typedef virDomainEventGraphicsAddress *virDomainEventGraphicsAddressPtr;
@@ -4520,8 +4520,8 @@ typedef virDomainEventGraphicsAddress *virDomainEventGraphicsAddressPtr;
  * some examples are 'x509dname' and 'saslUsername'.
  */
 struct _virDomainEventGraphicsSubjectIdentity {
-    const char *type;     /* Type of identity */
-    const char *name;     /* Identity value */
+    char *type;     /* Type of identity */
+    char *name;     /* Identity value */
 };
 typedef struct _virDomainEventGraphicsSubjectIdentity virDomainEventGraphicsSubjectIdentity;
 typedef virDomainEventGraphicsSubjectIdentity *virDomainEventGraphicsSubjectIdentityPtr;
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index a3a8d1f..0c7d237 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -362,7 +362,7 @@ virQEMUCapsParseMachineTypesStr(const char *output,
         if (!(t = strchr(p, ' ')) || (next && t >= next))
             continue;
 
-        if (!(name = strndup(p, t - p)))
+        if (VIR_STRNDUP(name, p, t - p) < 0)
             goto no_memory;
 
         p = t;
@@ -374,7 +374,7 @@ virQEMUCapsParseMachineTypesStr(const char *output,
             if (!(t = strchr(p, ')')) || (next && t >= next))
                 continue;
 
-            if (!(canonical = strndup(p, t - p))) {
+            if (VIR_STRNDUP(canonical, p, t - p) < 0) {
                 VIR_FREE(name);
                 goto no_memory;
             }
@@ -499,7 +499,7 @@ virQEMUCapsParseX86Models(const char *output,
             len -= 2;
         }
 
-        if (!(qemuCaps->cpuDefinitions[qemuCaps->ncpuDefinitions - 1] = strndup(p, len))) {
+        if (VIR_STRNDUP(qemuCaps->cpuDefinitions[qemuCaps->ncpuDefinitions - 1], p, len) < 0) {
             virReportOOMError();
             goto cleanup;
         }
@@ -552,7 +552,7 @@ virQEMUCapsParsePPCModels(const char *output,
 
         len = t - p - 1;
 
-        if (!(qemuCaps->cpuDefinitions[qemuCaps->ncpuDefinitions - 1] = strndup(p, len))) {
+        if (VIR_STRNDUP(qemuCaps->cpuDefinitions[qemuCaps->ncpuDefinitions - 1], p, len) < 0) {
             virReportOOMError();
             goto cleanup;
         }
@@ -1498,7 +1498,7 @@ virQEMUCapsParseDeviceStrObjectTypes(const char *str,
             virReportOOMError();
             goto cleanup;
         }
-        if (!(typelist[ntypelist-1] = strndup(tmp, end-tmp))) {
+        if (VIR_STRNDUP(typelist[ntypelist-1], tmp, end-tmp) < 0) {
             virReportOOMError();
             goto cleanup;
         }
@@ -1555,7 +1555,7 @@ virQEMUCapsParseDeviceStrObjectProps(const char *str,
             virReportOOMError();
             goto cleanup;
         }
-        if (!(proplist[nproplist-1] = strndup(tmp, end-tmp))) {
+        if (VIR_STRNDUP(proplist[nproplist-1], tmp, end-tmp) < 0) {
             virReportOOMError();
             goto cleanup;
         }
@@ -1726,7 +1726,7 @@ virQEMUCapsPtr virQEMUCapsNewCopy(virQEMUCapsPtr qemuCaps)
         goto no_memory;
     ret->ncpuDefinitions = qemuCaps->ncpuDefinitions;
     for (i = 0 ; i < qemuCaps->ncpuDefinitions ; i++) {
-        if (!(ret->cpuDefinitions[i] = strdup(qemuCaps->cpuDefinitions[i])))
+        if (VIR_STRDUP(ret->cpuDefinitions[i], qemuCaps->cpuDefinitions[i]) < 0)
             goto no_memory;
     }
 
@@ -1736,10 +1736,10 @@ virQEMUCapsPtr virQEMUCapsNewCopy(virQEMUCapsPtr qemuCaps)
         goto no_memory;
     ret->nmachineTypes = qemuCaps->nmachineTypes;
     for (i = 0 ; i < qemuCaps->nmachineTypes ; i++) {
-        if (!(ret->machineTypes[i] = strdup(qemuCaps->machineTypes[i])))
+        if (VIR_STRDUP(ret->machineTypes[i], qemuCaps->machineTypes[i]) < 0)
             goto no_memory;
         if (qemuCaps->machineAliases[i] &&
-            !(ret->machineAliases[i] = strdup(qemuCaps->machineAliases[i])))
+            VIR_STRDUP(ret->machineAliases[i], qemuCaps->machineAliases[i]) < 0)
             goto no_memory;
     }
 
@@ -1848,8 +1848,9 @@ unsigned int virQEMUCapsGetKVMVersion(virQEMUCapsPtr qemuCaps)
 int virQEMUCapsAddCPUDefinition(virQEMUCapsPtr qemuCaps,
                                 const char *name)
 {
-    char *tmp = strdup(name);
-    if (!tmp) {
+    char *tmp;
+
+    if (VIR_STRDUP(tmp, name) < 0) {
         virReportOOMError();
         return -1;
     }
@@ -1897,12 +1898,12 @@ int virQEMUCapsGetMachineTypesCaps(virQEMUCapsPtr qemuCaps,
         if (VIR_ALLOC(mach) < 0)
             goto no_memory;
         if (qemuCaps->machineAliases[i]) {
-            if (!(mach->name = strdup(qemuCaps->machineAliases[i])))
+            if (VIR_STRDUP(mach->name, qemuCaps->machineAliases[i]) < 0)
                 goto no_memory;
-            if (!(mach->canonical = strdup(qemuCaps->machineTypes[i])))
+            if (VIR_STRDUP(mach->canonical, qemuCaps->machineTypes[i]) < 0)
                 goto no_memory;
         } else {
-            if (!(mach->name = strdup(qemuCaps->machineTypes[i])))
+            if (VIR_STRDUP(mach->name, qemuCaps->machineTypes[i]) < 0)
                 goto no_memory;
         }
         (*machines)[i] = mach;
@@ -2092,12 +2093,12 @@ virQEMUCapsProbeQMPMachineTypes(virQEMUCapsPtr qemuCaps,
 
     for (i = 0 ; i < nmachines ; i++) {
         if (machines[i]->alias) {
-            if (!(qemuCaps->machineAliases[i] = strdup(machines[i]->alias))) {
+            if (VIR_STRDUP(qemuCaps->machineAliases[i], machines[i]->alias) < 0) {
                 virReportOOMError();
                 goto cleanup;
             }
         }
-        if (!(qemuCaps->machineTypes[i] = strdup(machines[i]->name))) {
+        if (VIR_STRDUP(qemuCaps->machineTypes[i], machines[i]->name) < 0) {
             virReportOOMError();
             goto cleanup;
         }
@@ -2590,7 +2591,7 @@ virQEMUCapsPtr virQEMUCapsNewForBinary(const char *binary,
     struct stat sb;
     int rv;
 
-    if (!(qemuCaps->binary = strdup(binary)))
+    if (VIR_STRDUP(qemuCaps->binary, binary) < 0)
         goto no_memory;
 
     /* We would also want to check faccessat if we cared about ACLs,
@@ -2672,7 +2673,7 @@ virQEMUCapsCacheNew(const char *libDir,
 
     if (!(cache->binaries = virHashCreate(10, virQEMUCapsHashDataFree)))
         goto error;
-    if (!(cache->libDir = strdup(libDir))) {
+    if (VIR_STRDUP(cache->libDir, libDir) < 0) {
         virReportOOMError();
         goto error;
     }
diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c
index 386751b..7a25db1 100644
--- a/src/qemu/qemu_cgroup.c
+++ b/src/qemu/qemu_cgroup.c
@@ -31,6 +31,7 @@
 #include "viralloc.h"
 #include "virerror.h"
 #include "domain_audit.h"
+#include "virstring.h"
 
 #define VIR_FROM_THIS VIR_FROM_QEMU
 
@@ -235,7 +236,7 @@ int qemuInitCgroup(virQEMUDriverPtr driver,
             goto cleanup;
         }
 
-        if (!(res->partition = strdup("/machine"))) {
+        if (VIR_STRDUP(res->partition, "/machine") < 0) {
             virReportOOMError();
             VIR_FREE(res);
             goto cleanup;
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index e2201ec..74fb9eb 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -322,7 +322,7 @@ qemuNetworkIfaceConnect(virDomainDefPtr def,
             return -1;
 
     } else if (actualType == VIR_DOMAIN_NET_TYPE_BRIDGE) {
-        if (!(brname = strdup(virDomainNetGetActualBridgeName(net)))) {
+        if (VIR_STRDUP(brname, virDomainNetGetActualBridgeName(net)) < 0) {
             virReportOOMError();
             return -1;
         }
@@ -337,7 +337,7 @@ qemuNetworkIfaceConnect(virDomainDefPtr def,
         STRPREFIX(net->ifname, VIR_NET_GENERATED_PREFIX) ||
         strchr(net->ifname, '%')) {
         VIR_FREE(net->ifname);
-        if (!(net->ifname = strdup(VIR_NET_GENERATED_PREFIX "%d"))) {
+        if (VIR_STRDUP(net->ifname, VIR_NET_GENERATED_PREFIX "%d") < 0) {
             virReportOOMError();
             goto cleanup;
         }
@@ -485,14 +485,15 @@ int qemuDomainNetVLAN(virDomainNetDefPtr def)
 static int qemuAssignDeviceDiskAliasLegacy(virDomainDiskDefPtr disk)
 {
     char *dev_name;
+    int rc;
 
     if (disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM &&
         STREQ(disk->dst, "hdc"))
-        dev_name = strdup("cdrom");
+        rc = VIR_STRDUP(dev_name, "cdrom");
     else
-        dev_name = strdup(disk->dst);
+        rc = VIR_STRDUP(dev_name, disk->dst);
 
-    if (!dev_name) {
+    if (rc < 0) {
         virReportOOMError();
         return -1;
     }
@@ -513,7 +514,7 @@ char *qemuDeviceDriveHostAlias(virDomainDiskDefPtr disk,
             return NULL;
         }
     } else {
-        if (!(ret = strdup(disk->info.alias))) {
+        if (VIR_STRDUP(ret, disk->info.alias) < 0) {
             virReportOOMError();
             return NULL;
         }
@@ -2418,14 +2419,10 @@ static int qemuAddRBDHost(virDomainDiskDefPtr disk, char *hostport)
     if (port) {
         *port = '\0';
         port += skip;
-        disk->hosts[disk->nhosts-1].port = strdup(port);
-        if (!disk->hosts[disk->nhosts-1].port)
-            goto no_memory;
-    } else {
-        disk->hosts[disk->nhosts-1].port = strdup("6789");
-        if (!disk->hosts[disk->nhosts-1].port)
+        if (VIR_STRDUP(disk->hosts[disk->nhosts-1].port, port) < 0)
             goto no_memory;
-    }
+    } else if (VIR_STRDUP(disk->hosts[disk->nhosts-1].port, "6789") < 0)
+        goto no_memory;
 
     parts = virStringSplit(hostport, "\\:", 0);
     if (!parts)
@@ -2455,8 +2452,7 @@ static int qemuParseRBDString(virDomainDiskDefPtr disk)
 
     p = strchr(disk->src, ':');
     if (p) {
-        options = strdup(p + 1);
-        if (!options)
+        if (VIR_STRDUP(options, p + 1) < 0)
             goto no_memory;
         *p = '\0';
     }
@@ -2482,11 +2478,10 @@ static int qemuParseRBDString(virDomainDiskDefPtr disk)
             *e = '\0';
         }
 
-        if (STRPREFIX(p, "id=")) {
-            disk->auth.username = strdup(p + strlen("id="));
-            if (!disk->auth.username)
-                goto no_memory;
-        }
+        if (STRPREFIX(p, "id=") &&
+            VIR_STRDUP(disk->auth.username, p + strlen("id=")) < 0)
+            goto no_memory;
+
         if (STRPREFIX(p, "mon_host=")) {
             char *h, *sep;
 
@@ -2555,8 +2550,7 @@ qemuParseDriveURIString(virDomainDiskDefPtr def, virURIPtr uri,
     def->nhosts = 0; /* set to 1 once everything succeeds */
 
     if (def->hosts->transport != VIR_DOMAIN_DISK_PROTO_TRANS_UNIX) {
-        def->hosts->name = strdup(uri->server);
-        if (!def->hosts->name)
+        if (VIR_STRDUP(def->hosts->name, uri->server) < 0)
             goto no_memory;
 
         if (virAsprintf(&def->hosts->port, "%d", uri->port) < 0)
@@ -2567,8 +2561,7 @@ qemuParseDriveURIString(virDomainDiskDefPtr def, virURIPtr uri,
         if (uri->query) {
             if (STRPREFIX(uri->query, "socket=")) {
                 sock = strchr(uri->query, '=') + 1;
-                def->hosts->socket = strdup(sock);
-                if (!def->hosts->socket)
+                if (VIR_STRDUP(def->hosts->socket, sock) < 0)
                     goto no_memory;
             } else {
                 virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -2580,8 +2573,7 @@ qemuParseDriveURIString(virDomainDiskDefPtr def, virURIPtr uri,
     if (uri->path) {
         volimg = uri->path + 1; /* skip the prefix slash */
         VIR_FREE(def->src);
-        def->src = strdup(volimg);
-        if (!def->src)
+        if (VIR_STRDUP(def->src, volimg) < 0)
             goto no_memory;
     } else {
         VIR_FREE(def->src);
@@ -2593,8 +2585,7 @@ qemuParseDriveURIString(virDomainDiskDefPtr def, virURIPtr uri,
         if (secret)
             *secret = '\0';
 
-        def->auth.username = strdup(uri->user);
-        if (!def->auth.username)
+        if (VIR_STRDUP(def->auth.username, uri->user) < 0)
             goto no_memory;
     }
 
@@ -2675,7 +2666,8 @@ qemuParseNBDString(virDomainDiskDefPtr disk)
             *src++ = '\0';
 
         h->transport = VIR_DOMAIN_DISK_PROTO_TRANS_UNIX;
-        h->socket = strdup(host + strlen("unix:"));
+        if (VIR_STRDUP(h->socket, host + strlen("unix:")) < 0)
+            goto no_memory;
     } else {
         port = strchr(host, ':');
         if (!port) {
@@ -2685,22 +2677,19 @@ qemuParseNBDString(virDomainDiskDefPtr disk)
         }
 
         *port++ = '\0';
-        h->name = strdup(host);
-        if (!h->name)
+        if (VIR_STRDUP(h->name, host) < 0)
             goto no_memory;
 
         src = strchr(port, ':');
         if (src)
             *src++ = '\0';
 
-        h->port = strdup(port);
-        if (!h->port)
+        if (VIR_STRDUP(h->port, port) < 0)
             goto no_memory;
     }
 
     if (src && STRPREFIX(src, "exportname=")) {
-        src = strdup(strchr(src, '=') + 1);
-        if (!src)
+        if (VIR_STRDUP(src, strchr(src, '=') + 1) < 0)
             goto no_memory;
     } else {
         src = NULL;
@@ -2751,8 +2740,7 @@ qemuBuildDriveURIString(virConnectPtr conn,
     transp = virDomainDiskProtocolTransportTypeToString(disk->hosts->transport);
 
     if (disk->hosts->transport == VIR_DOMAIN_DISK_PROTO_TRANS_TCP) {
-        tmpscheme = strdup(scheme);
-        if (tmpscheme == NULL)
+        if (VIR_STRDUP(tmpscheme, scheme) < 0)
             goto no_memory;
     } else {
         if (virAsprintf(&tmpscheme, "%s+%s", scheme, transp) < 0)
@@ -5454,7 +5442,7 @@ qemuBuildCpuArgStr(const virQEMUDriverPtr driver,
             virBufferAddLit(&buf, "host");
         } else {
             if (VIR_ALLOC(guest) < 0 ||
-                (cpu->vendor_id && !(guest->vendor_id = strdup(cpu->vendor_id))))
+                (cpu->vendor_id && VIR_STRDUP(guest->vendor_id, cpu->vendor_id) < 0))
                 goto no_memory;
 
             guest->arch = host->arch;
@@ -7035,10 +7023,8 @@ qemuBuildCommandLine(virConnectPtr conn,
             } else if (disk->type == VIR_DOMAIN_DISK_TYPE_NETWORK) {
                 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                                _("network disks are only supported with -drive"));
-            } else {
-                if (!(file = strdup(disk->src))) {
-                    goto no_memory;
-                }
+            } else if (VIR_STRDUP(file, disk->src) < 0) {
+                goto no_memory;
             }
 
             /* Don't start with source if the tray is open for
@@ -7872,7 +7858,7 @@ qemuBuildCommandLine(virConnectPtr conn,
                 goto error;
             }
 
-            if (!(optstr = strdup(model)))
+            if (VIR_STRDUP(optstr, model) < 0)
                 goto no_memory;
         }
         virCommandAddArg(cmd, optstr);
@@ -8308,12 +8294,14 @@ static int qemuStringToArgvEnv(const char *args,
             next = strchr(curr, '\n');
 
         if (next) {
-            arg = strndup(curr, next-curr);
+            if (VIR_STRNDUP(arg, curr, next-curr) < 0)
+                goto no_memory;
             if (*next == '\'' ||
                 *next == '"')
                 next++;
         } else {
-            arg = strdup(curr);
+            if (VIR_STRDUP(arg, curr) < 0)
+                goto no_memory;
         }
 
         if (!arg)
@@ -8448,12 +8436,12 @@ qemuParseKeywords(const char *str,
             separator = endmark;
         }
 
-        if (!(keyword = strndup(start, separator - start)))
+        if (VIR_STRNDUP(keyword, start, separator - start) < 0)
             goto no_memory;
 
         if (separator < endmark) {
             separator++;
-            if (!(value = strndup(separator, endmark - separator))) {
+            if (VIR_STRNDUP(value, separator, endmark - separator) < 0) {
                 VIR_FREE(keyword);
                 goto no_memory;
             }
@@ -8525,6 +8513,7 @@ qemuParseCommandLineDisk(virDomainXMLOptionPtr xmlopt,
     int busid = -1;
     int unitid = -1;
     int trans = VIR_DOMAIN_DISK_TRANS_DEFAULT;
+    int rc;
 
     if ((nkeywords = qemuParseKeywords(val,
                                        &keywords,
@@ -8560,8 +8549,7 @@ qemuParseCommandLineDisk(virDomainXMLOptionPtr xmlopt,
 
                     def->type = VIR_DOMAIN_DISK_TYPE_NETWORK;
                     def->protocol = VIR_DOMAIN_DISK_PROTOCOL_RBD;
-                    def->src = strdup(p + strlen("rbd:"));
-                    if (!def->src) {
+                    if (VIR_STRDUP(def->src, p + strlen("rbd:")) < 0) {
                         virReportOOMError();
                         goto error;
                     }
@@ -8589,8 +8577,7 @@ qemuParseCommandLineDisk(virDomainXMLOptionPtr xmlopt,
 
                     def->type = VIR_DOMAIN_DISK_TYPE_NETWORK;
                     def->protocol = VIR_DOMAIN_DISK_PROTOCOL_SHEEPDOG;
-                    def->src = strdup(p + strlen("sheepdog:"));
-                    if (!def->src) {
+                    if (VIR_STRDUP(def->src, p + strlen("sheepdog:")) < 0) {
                         virReportOOMError();
                         goto error;
                     }
@@ -8612,15 +8599,13 @@ qemuParseCommandLineDisk(virDomainXMLOptionPtr xmlopt,
                         }
                         def->nhosts = 1;
                         def->hosts->name = def->src;
-                        def->hosts->port = strdup(port);
-                        if (!def->hosts->port) {
+                        if (VIR_STRDUP(def->hosts->port, port) < 0) {
                             virReportOOMError();
                             goto error;
                         }
                         def->hosts->transport = VIR_DOMAIN_DISK_PROTO_TRANS_TCP;
                         def->hosts->socket = NULL;
-                        def->src = strdup(vdi);
-                        if (!def->src) {
+                        if (VIR_STRDUP(def->src, vdi) < 0) {
                             virReportOOMError();
                             goto error;
                         }
@@ -8648,8 +8633,7 @@ qemuParseCommandLineDisk(virDomainXMLOptionPtr xmlopt,
             } else if (STREQ(values[i], "floppy"))
                 def->device = VIR_DOMAIN_DISK_DEVICE_FLOPPY;
         } else if (STREQ(keywords[i], "format")) {
-            def->driverName = strdup("qemu");
-            if (!def->driverName) {
+            if (VIR_STRDUP(def->driverName, "qemu") < 0) {
                 virReportOOMError();
                 goto error;
             }
@@ -8792,18 +8776,18 @@ qemuParseCommandLineDisk(virDomainXMLOptionPtr xmlopt,
     }
 
     if (def->bus == VIR_DOMAIN_DISK_BUS_IDE) {
-        def->dst = strdup("hda");
+        rc = VIR_STRDUP(def->dst, "hda");
     } else if (def->bus == VIR_DOMAIN_DISK_BUS_SCSI) {
-        def->dst = strdup("sda");
+        rc = VIR_STRDUP(def->dst, "sda");
     } else if (def->bus == VIR_DOMAIN_DISK_BUS_VIRTIO) {
-        def->dst = strdup("vda");
+        rc = VIR_STRDUP(def->dst, "vda");
     } else if (def->bus == VIR_DOMAIN_DISK_BUS_XEN) {
-        def->dst = strdup("xvda");
+        rc = VIR_STRDUP(def->dst, "xvda");
     } else {
-        def->dst = strdup("hda");
+        rc = VIR_STRDUP(def->dst, "hda");
     }
 
-    if (!def->dst) {
+    if (rc < 0) {
         virReportOOMError();
         goto error;
     }
@@ -9158,13 +9142,11 @@ qemuParseCommandLineChr(virDomainChrSourceDefPtr source,
         source->type = VIR_DOMAIN_CHR_TYPE_PTY;
     } else if (STRPREFIX(val, "file:")) {
         source->type = VIR_DOMAIN_CHR_TYPE_FILE;
-        source->data.file.path = strdup(val+strlen("file:"));
-        if (!source->data.file.path)
+        if (VIR_STRDUP(source->data.file.path, val+strlen("file:")) < 0)
             goto no_memory;
     } else if (STRPREFIX(val, "pipe:")) {
         source->type = VIR_DOMAIN_CHR_TYPE_PIPE;
-        source->data.file.path = strdup(val+strlen("pipe:"));
-        if (!source->data.file.path)
+        if (VIR_STRDUP(source->data.file.path, val+strlen("pipe:")) < 0)
             goto no_memory;
     } else if (STREQ(val, "stdio")) {
         source->type = VIR_DOMAIN_CHR_TYPE_STDIO;
@@ -9177,40 +9159,30 @@ qemuParseCommandLineChr(virDomainChrSourceDefPtr source,
         svc2 = host2 ? strchr(host2, ':') : NULL;
 
         if (svc1 && (svc1 != val)) {
-            source->data.udp.connectHost = strndup(val, svc1-val);
-
-            if (!source->data.udp.connectHost)
+            if (VIR_STRNDUP(source->data.udp.connectHost, val, svc1-val) < 0)
                 goto no_memory;
         }
 
         if (svc1) {
             svc1++;
-            if (host2)
-                source->data.udp.connectService = strndup(svc1, host2-svc1);
-            else
-                source->data.udp.connectService = strdup(svc1);
-
-            if (!source->data.udp.connectService)
+            if ((host2 && VIR_STRNDUP(source->data.udp.connectService, svc1, host2-svc1) < 0) ||
+                (!host2 && VIR_STRDUP(source->data.udp.connectService, svc1) < 0))
                 goto no_memory;
         }
 
         if (host2) {
             host2++;
             if (svc2 && (svc2 != host2)) {
-                source->data.udp.bindHost = strndup(host2, svc2-host2);
-
-                if (!source->data.udp.bindHost)
+                if (VIR_STRNDUP(source->data.udp.bindHost, host2, svc2-host2) < 0)
                     goto no_memory;
             }
         }
 
         if (svc2) {
             svc2++;
-            if (STRNEQ(svc2, "0")) {
-                source->data.udp.bindService = strdup(svc2);
-                if (!source->data.udp.bindService)
-                    goto no_memory;
-            }
+            if (STRNEQ(svc2, "0") &&
+                VIR_STRDUP(source->data.udp.bindService, svc2) < 0)
+                goto no_memory;
         }
     } else if (STRPREFIX(val, "tcp:") ||
                STRPREFIX(val, "telnet:")) {
@@ -9232,16 +9204,11 @@ qemuParseCommandLineChr(virDomainChrSourceDefPtr source,
         if (opt && strstr(opt, "server"))
             source->data.tcp.listen = true;
 
-        source->data.tcp.host = strndup(val, svc-val);
-        if (!source->data.tcp.host)
+        if (VIR_STRNDUP(source->data.tcp.host, val, svc-val) < 0)
             goto no_memory;
         svc++;
-        if (opt) {
-            source->data.tcp.service = strndup(svc, opt-svc);
-        } else {
-            source->data.tcp.service = strdup(svc);
-        }
-        if (!source->data.tcp.service)
+        if ((opt && VIR_STRNDUP(source->data.tcp.service, svc, opt-svc) < 0) ||
+            (!opt && VIR_STRDUP(source->data.tcp.service, svc) < 0))
             goto no_memory;
     } else if (STRPREFIX(val, "unix:")) {
         const char *opt;
@@ -9251,17 +9218,14 @@ qemuParseCommandLineChr(virDomainChrSourceDefPtr source,
         if (opt) {
             if (strstr(opt, "listen"))
                 source->data.nix.listen = true;
-            source->data.nix.path = strndup(val, opt-val);
-        } else {
-            source->data.nix.path = strdup(val);
-        }
-        if (!source->data.nix.path)
+            if (VIR_STRNDUP(source->data.nix.path, val, opt-val) < 0)
+                goto no_memory;
+        } else if (VIR_STRDUP(source->data.nix.path, val) < 0)
             goto no_memory;
 
     } else if (STRPREFIX(val, "/dev")) {
         source->type = VIR_DOMAIN_CHR_TYPE_DEV;
-        source->data.file.path = strdup(val);
-        if (!source->data.file.path)
+        if (VIR_STRDUP(source->data.file.path, val) < 0)
             goto no_memory;
     } else {
         virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -9315,12 +9279,8 @@ qemuParseCommandLineCPU(virDomainDefPtr dom,
             next++;
 
         if (p == val) {
-            if (next)
-                model = strndup(p, next - p - 1);
-            else
-                model = strdup(p);
-
-            if (!model)
+            if ((next && VIR_STRNDUP(model, p, next - p - 1) < 0) ||
+                (!next && VIR_STRDUP(model, p) < 0))
                 goto no_memory;
 
             if (!STREQ(model, "qemu32") && !STREQ(model, "qemu64")) {
@@ -9344,12 +9304,8 @@ qemuParseCommandLineCPU(virDomainDefPtr dom,
             if (*p == '\0' || *p == ',')
                 goto syntax;
 
-            if (next)
-                feature = strndup(p, next - p - 1);
-            else
-                feature = strdup(p);
-
-            if (!feature)
+            if ((next && VIR_STRNDUP(feature, p, next - p - 1) < 0) ||
+                (!next && VIR_STRDUP(feature, p) < 0))
                 goto no_memory;
 
             if (STREQ(feature, "kvmclock")) {
@@ -9408,12 +9364,8 @@ qemuParseCommandLineCPU(virDomainDefPtr dom,
             if (*p == '\0' || *p == ',')
                 goto syntax;
 
-            if (next)
-                feature = strndup(p, next - p - 1);
-            else
-                feature = strdup(p);
-
-            if (!feature)
+            if ((next && VIR_STRNDUP(feature, p, next - p - 1) < 0) ||
+                (!next && VIR_STRDUP(feature, p) < 0))
                 goto no_memory;
 
             dom->features |= (1 << VIR_DOMAIN_FEATURE_HYPERV);
@@ -9632,7 +9584,7 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps,
     def->onCrash = VIR_DOMAIN_LIFECYCLE_DESTROY;
     def->onPoweroff = VIR_DOMAIN_LIFECYCLE_DESTROY;
     def->virtType = VIR_DOMAIN_VIRT_QEMU;
-    if (!(def->emulator = strdup(progargv[0])))
+    if (VIR_STRDUP(def->emulator, progargv[0]) < 0)
         goto no_memory;
 
     if (strstr(def->emulator, "kvm")) {
@@ -9643,11 +9595,9 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps,
 
     if (strstr(def->emulator, "xenner")) {
         def->virtType = VIR_DOMAIN_VIRT_KVM;
-        def->os.type = strdup("xen");
-    } else {
-        def->os.type = strdup("hvm");
-    }
-    if (!def->os.type)
+        if (VIR_STRDUP(def->os.type, "xen") < 0)
+            goto no_memory;
+    } else if (VIR_STRDUP(def->os.type, "hvm") < 0)
         goto no_memory;
 
     if (STRPREFIX(def->emulator, "qemu"))
@@ -9711,8 +9661,7 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps,
 
             if (STRPREFIX(val, "unix:")) {
                 /* -vnc unix:/some/big/path */
-                vnc->data.vnc.socket = strdup(val + 5);
-                if (!vnc->data.vnc.socket) {
+                if (VIR_STRDUP(vnc->data.vnc.socket, val + 5) < 0) {
                     virDomainGraphicsDefFree(vnc);
                     goto no_memory;
                 }
@@ -9809,8 +9758,7 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps,
                 disk->type = VIR_DOMAIN_DISK_TYPE_FILE;
             if (STREQ(arg, "-cdrom")) {
                 disk->device = VIR_DOMAIN_DISK_DEVICE_CDROM;
-                disk->dst = strdup("hdc");
-                if (!disk->dst)
+                if (VIR_STRDUP(disk->dst, "hdc") < 0)
                     goto no_memory;
                 disk->readonly = true;
             } else {
@@ -9824,12 +9772,10 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps,
                     else
                         disk->bus = VIR_DOMAIN_DISK_BUS_SCSI;
                 }
-                disk->dst = strdup(arg + 1);
-                if (!disk->dst)
+                if (VIR_STRDUP(disk->dst, arg + 1) < 0)
                     goto no_memory;
             }
-            disk->src = strdup(val);
-            if (!disk->src)
+            if (VIR_STRDUP(disk->src, val) < 0)
                 goto no_memory;
 
             if (disk->type == VIR_DOMAIN_DISK_TYPE_NETWORK) {
@@ -9863,11 +9809,9 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps,
                             goto no_memory;
                         disk->nhosts = 1;
                         disk->hosts->name = disk->src;
-                        disk->hosts->port = strdup(port);
-                        if (!disk->hosts->port)
+                        if (VIR_STRDUP(disk->hosts->port, port) < 0)
                             goto no_memory;
-                        disk->src = strdup(vdi);
-                        if (!disk->src)
+                        if (VIR_STRDUP(disk->src, vdi) < 0)
                             goto no_memory;
                     }
                     break;
@@ -9915,23 +9859,23 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps,
             def->clock.offset = VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME;
         } else if (STREQ(arg, "-kernel")) {
             WANT_VALUE();
-            if (!(def->os.kernel = strdup(val)))
+            if (VIR_STRDUP(def->os.kernel, val) < 0)
                 goto no_memory;
         } else if (STREQ(arg, "-bios")) {
             WANT_VALUE();
-            if (!(def->os.loader = strdup(val)))
+            if (VIR_STRDUP(def->os.loader, val) < 0)
                 goto no_memory;
         } else if (STREQ(arg, "-initrd")) {
             WANT_VALUE();
-            if (!(def->os.initrd = strdup(val)))
+            if (VIR_STRDUP(def->os.initrd, val) < 0)
                 goto no_memory;
         } else if (STREQ(arg, "-append")) {
             WANT_VALUE();
-            if (!(def->os.cmdline = strdup(val)))
+            if (VIR_STRDUP(def->os.cmdline, val) < 0)
                 goto no_memory;
         } else if (STREQ(arg, "-dtb")) {
             WANT_VALUE();
-            if (!(def->os.dtb = strdup(val)))
+            if (VIR_STRDUP(def->os.dtb, val) < 0)
                 goto no_memory;
         } else if (STREQ(arg, "-boot")) {
             const char *token = NULL;
@@ -9976,10 +9920,10 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps,
             WANT_VALUE();
             process = strstr(val, ",process=");
             if (process == NULL) {
-                if (!(def->name = strdup(val)))
+                if (VIR_STRDUP(def->name, val) < 0)
                     goto no_memory;
             } else {
-                if (!(def->name = strndup(val, process - val)))
+                if (VIR_STRNDUP(def->name, val, process - val) < 0)
                     goto no_memory;
             }
             if (STREQ(def->name, ""))
@@ -9990,10 +9934,10 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps,
             WANT_VALUE();
             params = strchr(val, ',');
             if (params == NULL) {
-                if (!(def->os.machine = strdup(val)))
+                if (VIR_STRDUP(def->os.machine, val) < 0)
                     goto no_memory;
             } else {
-                if (!(def->os.machine = strndup(val, params - val)))
+                if (VIR_STRNDUP(def->os.machine, val, params - val) < 0)
                     goto no_memory;
 
                 while (params++) {
@@ -10003,11 +9947,8 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps,
 
                     if (STRPREFIX(tmp, "dump-guest-core=")) {
                         tmp += strlen("dump-guest-core=");
-                        if (params) {
-                            tmp = strndup(tmp, params - tmp);
-                            if (tmp == NULL)
-                                goto no_memory;
-                        }
+                        if (params && VIR_STRNDUP(tmp, tmp, params - tmp) < 0)
+                            goto no_memory;
                         def->mem.dump_core = virDomainMemDumpTypeFromString(tmp);
                         if (def->mem.dump_core <= 0)
                             def->mem.dump_core = VIR_DOMAIN_MEM_DUMP_DEFAULT;
@@ -10076,8 +10017,7 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps,
             } else if (STRPREFIX(val, "disk:")) {
                 if (VIR_ALLOC(disk) < 0)
                     goto no_memory;
-                disk->src = strdup(val + strlen("disk:"));
-                if (!disk->src)
+                if (VIR_STRDUP(disk->src, val + strlen("disk:")) < 0)
                     goto no_memory;
                 if (STRPREFIX(disk->src, "/dev/"))
                     disk->type = VIR_DOMAIN_DISK_TYPE_BLOCK;
@@ -10085,7 +10025,7 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps,
                     disk->type = VIR_DOMAIN_DISK_TYPE_FILE;
                 disk->device = VIR_DOMAIN_DISK_DEVICE_DISK;
                 disk->bus = VIR_DOMAIN_DISK_BUS_USB;
-                if (!(disk->dst = strdup("sda")) ||
+                if (VIR_STRDUP(disk->dst, "sda") < 0 ||
                     VIR_REALLOC_N(def->disks, def->ndisks+1) < 0)
                     goto no_memory;
                 def->disks[def->ndisks++] = disk;
@@ -10188,8 +10128,7 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps,
                 def->watchdog->action = action;
         } else if (STREQ(arg, "-bootloader")) {
             WANT_VALUE();
-            def->os.bootloader = strdup(val);
-            if (!def->os.bootloader)
+            if (VIR_STRDUP(def->os.bootloader, val) < 0)
                 goto no_memory;
         } else if (STREQ(arg, "-vmwarevga")) {
             video = VIR_DOMAIN_VIDEO_TYPE_VMVGA;
@@ -10223,7 +10162,7 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps,
         } else if (STREQ(arg, "-pidfile")) {
             WANT_VALUE();
             if (pidfile)
-                if (!(*pidfile = strdup(val)))
+                if (VIR_STRDUP(*pidfile, val) < 0)
                     goto no_memory;
         } else if (STREQ(arg, "-incoming")) {
             WANT_VALUE();
@@ -10306,8 +10245,7 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps,
                      arg);
             if (VIR_REALLOC_N(cmd->args, cmd->num_args+1) < 0)
                 goto no_memory;
-            cmd->args[cmd->num_args] = strdup(arg);
-            if (cmd->args[cmd->num_args] == NULL)
+            if (VIR_STRDUP(cmd->args[cmd->num_args], arg) < 0)
                 goto no_memory;
             cmd->num_args++;
         }
@@ -10337,8 +10275,7 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps,
                            _("could not parse CEPH_ARGS '%s'"), ceph_args);
             goto error;
         }
-        hosts = strdup(strchr(ceph_args, ' ') + 1);
-        if (!hosts)
+        if (VIR_STRDUP(hosts, strchr(ceph_args, ' ') + 1) < 0)
             goto no_memory;
         first_rbd_disk->nhosts = 0;
         token = strtok_r(hosts, ",", &saveptr);
@@ -10350,15 +10287,13 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps,
             port = strchr(token, ':');
             if (port) {
                 *port++ = '\0';
-                port = strdup(port);
-                if (!port) {
+                if (VIR_STRDUP(port, port) < 0) {
                     VIR_FREE(hosts);
                     goto no_memory;
                 }
             }
             first_rbd_disk->hosts[first_rbd_disk->nhosts].port = port;
-            first_rbd_disk->hosts[first_rbd_disk->nhosts].name = strdup(token);
-            if (!first_rbd_disk->hosts[first_rbd_disk->nhosts].name) {
+            if (VIR_STRDUP(first_rbd_disk->hosts[first_rbd_disk->nhosts].name, token) < 0) {
                 VIR_FREE(hosts);
                 goto no_memory;
             }
@@ -10384,7 +10319,7 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps,
                                                            def->os.arch,
                                                            virDomainVirtTypeToString(def->virtType));
         if (defaultMachine != NULL)
-            if (!(def->os.machine = strdup(defaultMachine)))
+            if (VIR_STRDUP(def->os.machine, defaultMachine) < 0)
                 goto no_memory;
     }
 
@@ -10397,12 +10332,12 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps,
         sdl->type = VIR_DOMAIN_GRAPHICS_TYPE_SDL;
         sdl->data.sdl.fullscreen = fullscreen;
         if (display &&
-            !(sdl->data.sdl.display = strdup(display))) {
+            VIR_STRDUP(sdl->data.sdl.display, display) < 0) {
             VIR_FREE(sdl);
             goto no_memory;
         }
         if (xauth &&
-            !(sdl->data.sdl.xauth = strdup(xauth))) {
+            VIR_STRDUP(sdl->data.sdl.xauth, xauth) < 0) {
             VIR_FREE(sdl);
             goto no_memory;
         }
@@ -10513,7 +10448,7 @@ cleanup:
 
 static int qemuParseProcFileStrings(int pid_value,
                                     const char *name,
-                                    const char ***list)
+                                    char ***list)
 {
     char *path = NULL;
     int ret = -1;
@@ -10521,7 +10456,7 @@ static int qemuParseProcFileStrings(int pid_value,
     ssize_t len;
     char *tmp;
     size_t nstr = 0;
-    const char **str = NULL;
+    char **str = NULL;
     int i;
 
     if (virAsprintf(&path, "/proc/%d/%s", pid_value, name) < 0) {
@@ -10539,7 +10474,7 @@ static int qemuParseProcFileStrings(int pid_value,
             goto cleanup;
         }
 
-        if (!(str[nstr-1] = strdup(tmp))) {
+        if (VIR_STRDUP(str[nstr-1], tmp) < 0) {
             virReportOOMError();
             goto cleanup;
         }
@@ -10578,8 +10513,8 @@ virDomainDefPtr qemuParseCommandLinePid(virCapsPtr qemuCaps,
                                         bool *monJSON)
 {
     virDomainDefPtr def = NULL;
-    const char **progargv = NULL;
-    const char **progenv = NULL;
+    char **progargv = NULL;
+    char **progenv = NULL;
     char *exepath = NULL;
     char *emulator;
     int i;
@@ -10591,7 +10526,9 @@ virDomainDefPtr qemuParseCommandLinePid(virCapsPtr qemuCaps,
         qemuParseProcFileStrings(pid, "environ", &progenv) < 0)
         goto cleanup;
 
-    if (!(def = qemuParseCommandLine(qemuCaps, xmlopt, progenv, progargv,
+    if (!(def = qemuParseCommandLine(qemuCaps, xmlopt,
+                                     (const char **) progenv,
+                                     (const char **) progargv,
                                      pidfile, monConfig, monJSON)))
         goto cleanup;
 
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index c16b90d..384516b 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -140,7 +140,7 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged)
                         "%s/log/libvirt/qemu", LOCALSTATEDIR) < 0)
             goto no_memory;
 
-        if ((cfg->configBaseDir = strdup(SYSCONFDIR "/libvirt")) == NULL)
+        if (VIR_STRDUP(cfg->configBaseDir, SYSCONFDIR "/libvirt") < 0)
             goto no_memory;
 
         if (virAsprintf(&cfg->stateDir,
@@ -210,18 +210,16 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged)
         goto no_memory;
 
 
-    if (!(cfg->vncListen = strdup("127.0.0.1")))
+    if (VIR_STRDUP(cfg->vncListen, "127.0.0.1") < 0)
         goto no_memory;
 
-    if (!(cfg->vncTLSx509certdir
-          = strdup(SYSCONFDIR "/pki/libvirt-vnc")))
+    if (VIR_STRDUP(cfg->vncTLSx509certdir, SYSCONFDIR "/pki/libvirt-vnc") < 0)
         goto no_memory;
 
-    if (!(cfg->spiceListen = strdup("127.0.0.1")))
+    if (VIR_STRDUP(cfg->spiceListen, "127.0.0.1") < 0)
         goto no_memory;
 
-    if (!(cfg->spiceTLSx509certdir
-          = strdup(SYSCONFDIR "/pki/libvirt-spice")))
+    if (VIR_STRDUP(cfg->spiceTLSx509certdir, SYSCONFDIR "/pki/libvirt-spice") < 0)
         goto no_memory;
 
     cfg->remotePortMin = QEMU_REMOTE_PORT_MIN;
@@ -240,7 +238,7 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged)
         }
     }
 #endif
-    if (!(cfg->bridgeHelperName = strdup("/usr/libexec/qemu-bridge-helper")))
+    if (VIR_STRDUP(cfg->bridgeHelperName, "/usr/libexec/qemu-bridge-helper") < 0)
         goto no_memory;
 
     cfg->clearEmulatorCapabilities = true;
@@ -347,7 +345,7 @@ int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPtr cfg,
     CHECK_TYPE(NAME, VIR_CONF_STRING);     \
     if (p && p->str) {                     \
         VIR_FREE(VAR);                     \
-        if (!(VAR = strdup(p->str)))       \
+        if (VIR_STRDUP(VAR, p->str) < 0)   \
             goto no_memory;                \
     }
 
@@ -379,7 +377,7 @@ int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPtr cfg,
             goto no_memory;
 
         for (i = 0, pp = p->list; pp; i++, pp = pp->next) {
-            if (!(cfg->securityDriverNames[i] = strdup(pp->str)))
+            if (VIR_STRDUP(cfg->securityDriverNames[i], pp->str) < 0)
                 goto no_memory;
         }
         cfg->securityDriverNames[len] = NULL;
@@ -387,7 +385,7 @@ int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPtr cfg,
         CHECK_TYPE("security_driver", VIR_CONF_STRING);
         if (p && p->str) {
             if (VIR_ALLOC_N(cfg->securityDriverNames, 2) < 0 ||
-                !(cfg->securityDriverNames[0] = strdup(p->str)))
+                VIR_STRDUP(cfg->securityDriverNames[0], p->str) < 0)
                 goto no_memory;
 
             cfg->securityDriverNames[1] = NULL;
@@ -486,7 +484,7 @@ int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPtr cfg,
                                  "list of strings"));
                 goto cleanup;
             }
-            if (!(cfg->cgroupDeviceACL[i] = strdup(pp->str)))
+            if (VIR_STRDUP(cfg->cgroupDeviceACL[i], pp->str) < 0)
                 goto no_memory;
         }
         cfg->cgroupDeviceACL[i] = NULL;
@@ -586,9 +584,9 @@ virCapsPtr virQEMUDriverCreateCapabilities(virQEMUDriverPtr driver)
     for (i = 0; sec_managers[i]; i++) {
         doi = virSecurityManagerGetDOI(sec_managers[i]);
         model = virSecurityManagerGetModel(sec_managers[i]);
-        if (!(caps->host.secModels[i].model = strdup(model)))
+        if (VIR_STRDUP(caps->host.secModels[i].model, model) < 0)
             goto no_memory;
-        if (!(caps->host.secModels[i].doi = strdup(doi)))
+        if (VIR_STRDUP(caps->host.secModels[i].doi, doi) < 0)
             goto no_memory;
         VIR_DEBUG("Initialized caps for security driver \"%s\" with "
                   "DOI \"%s\"", model, doi);
@@ -1070,7 +1068,7 @@ qemuSharedDiskEntryCopy(const qemuSharedDiskEntryPtr entry)
     }
 
     for (i = 0; i < entry->ref; i++) {
-        if (!(ret->domains[i] = strdup(entry->domains[i]))) {
+        if (VIR_STRDUP(ret->domains[i], entry->domains[i]) < 0) {
             virReportOOMError();
             goto cleanup;
         }
@@ -1135,7 +1133,7 @@ qemuAddSharedDisk(virQEMUDriverPtr driver,
             goto cleanup;
 
         if ((VIR_EXPAND_N(new_entry->domains, new_entry->ref, 1) < 0) ||
-            !(new_entry->domains[new_entry->ref - 1] = strdup(name))) {
+            VIR_STRDUP(new_entry->domains[new_entry->ref - 1], name) < 0) {
             qemuSharedDiskEntryFree(new_entry, NULL);
             virReportOOMError();
             goto cleanup;
@@ -1148,7 +1146,7 @@ qemuAddSharedDisk(virQEMUDriverPtr driver,
     } else {
         if ((VIR_ALLOC(entry) < 0) ||
             (VIR_ALLOC_N(entry->domains, 1) < 0) ||
-            !(entry->domains[0] = strdup(name))) {
+            VIR_STRDUP(entry->domains[0], name) < 0) {
             qemuSharedDiskEntryFree(entry, NULL);
             virReportOOMError();
             goto cleanup;
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index e31141a..0b08dae 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -731,13 +731,13 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
         dev->data.net->type != VIR_DOMAIN_NET_TYPE_HOSTDEV &&
         !dev->data.net->model) {
         if (def->os.arch == VIR_ARCH_S390 ||
-            def->os.arch == VIR_ARCH_S390X)
-            dev->data.net->model = strdup("virtio");
-        else
-            dev->data.net->model = strdup("rtl8139");
-
-        if (!dev->data.net->model)
-            goto no_memory;
+            def->os.arch == VIR_ARCH_S390X) {
+            if (VIR_STRDUP(dev->data.net->model, "virtio") < 0)
+                goto no_memory;
+        } else {
+            if (VIR_STRDUP(dev->data.net->model, "rtl8139") < 0)
+                goto no_memory;
+        }
     }
 
     /* set default disk types and drivers */
@@ -761,7 +761,7 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
             } else {
                 /* default driver if probing is forbidden */
                 if (!disk->driverName &&
-                    !(disk->driverName = strdup("qemu")))
+                    VIR_STRDUP(disk->driverName, "qemu") < 0)
                         goto no_memory;
 
                 /* default disk format for drives */
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 1e184dd..47ecccf 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -1441,7 +1441,7 @@ qemuCanonicalizeMachine(virDomainDefPtr def, virQEMUCapsPtr qemuCaps)
 
     if (STRNEQ(canon, def->os.machine)) {
         char *tmp;
-        if (!(tmp = strdup(canon))) {
+        if (VIR_STRDUP(tmp, canon) < 0) {
             virReportOOMError();
             return -1;
         }
@@ -2014,7 +2014,7 @@ static char *qemuDomainGetOSType(virDomainPtr dom) {
     if (!(vm = qemuDomObjFromDomain(dom)))
         goto cleanup;
 
-    if (!(type = strdup(vm->def->os.type)))
+    if (VIR_STRDUP(type, vm->def->os.type) < 0)
         virReportOOMError();
 
 cleanup:
@@ -3386,14 +3386,18 @@ qemuDomainScreenshot(virDomainPtr dom,
         goto endjob;
     }
 
+    if (VIR_STRDUP(ret, "image/x-portable-pixmap") < 0) {
+        virReportOOMError();
+        goto endjob;
+    }
+
     if (virFDStreamOpenFile(st, tmp, 0, 0, O_RDONLY) < 0) {
         virReportError(VIR_ERR_OPERATION_FAILED, "%s",
                        _("unable to open stream"));
+        VIR_FREE(ret);
         goto endjob;
     }
 
-    ret = strdup("image/x-portable-pixmap");
-
 endjob:
     VIR_FORCE_CLOSE(tmp_fd);
     if (unlink_tmp)
@@ -5140,8 +5144,7 @@ static char *qemuConnectDomainXMLFromNative(virConnectPtr conn,
     if (!def)
         goto cleanup;
 
-    if (!def->name &&
-        !(def->name = strdup("unnamed"))) {
+    if (!def->name && VIR_STRDUP(def->name, "unnamed") < 0) {
         virReportOOMError();
         goto cleanup;
     }
@@ -5210,8 +5213,8 @@ static char *qemuConnectDomainXMLToNative(virConnectPtr conn,
             if ((actualType == VIR_DOMAIN_NET_TYPE_BRIDGE) &&
                 (brname = virDomainNetGetActualBridgeName(net))) {
 
-                char *brnamecopy = strdup(brname);
-                if (!brnamecopy) {
+                char *brnamecopy;
+                if (VIR_STRDUP(brnamecopy, brname) < 0) {
                     virReportOOMError();
                     goto cleanup;
                 }
@@ -6631,8 +6634,7 @@ static char *qemuDomainGetSchedulerType(virDomainPtr dom,
             *nparams = 5;
     }
 
-    ret = strdup("posix");
-    if (!ret)
+    if (VIR_STRDUP(ret, "posix") < 0)
         virReportOOMError();
 
 cleanup:
@@ -6691,8 +6693,7 @@ qemuDomainParseDeviceWeightStr(char *deviceWeightStr,
         if (!p)
             goto error;
 
-        result[i].path = strndup(temp, p - temp);
-        if (!result[i].path) {
+        if (VIR_STRNDUP(result[i].path, temp, p - temp) < 0) {
             virReportOOMError();
             goto cleanup;
         }
@@ -7059,12 +7060,9 @@ qemuDomainGetBlkioParameters(virDomainPtr dom,
                     }
                     param->value.s = virBufferContentAndReset(&buf);
                 }
-                if (!param->value.s) {
-                    param->value.s = strdup("");
-                    if (!param->value.s) {
-                        virReportOOMError();
-                        goto cleanup;
-                    }
+                if (!param->value.s && VIR_STRDUP(param->value.s, "") < 0) {
+                    virReportOOMError();
+                    goto cleanup;
                 }
                 param->type = VIR_TYPED_PARAM_STRING;
                 if (virStrcpyStatic(param->field,
@@ -7587,8 +7585,10 @@ qemuDomainGetNumaParameters(virDomainPtr dom,
         case 1: /* fill numa nodeset here */
             if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
                 nodeset = virBitmapFormat(persistentDef->numatune.memory.nodemask);
-                if (!nodeset)
-                    nodeset = strdup("");
+                if (!nodeset && VIR_STRDUP(nodeset, "") < 0) {
+                    virReportOOMError();
+                    goto cleanup;
+                }
             } else {
                 rc = virCgroupGetCpusetMems(priv->cgroup, &nodeset);
                 if (rc != 0) {
@@ -10579,7 +10579,7 @@ qemuDomainSnapshotCreateInactiveExternal(virQEMUDriverPtr driver,
 
         if (snapdisk->snapshot == VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL) {
             VIR_FREE(defdisk->src);
-            if (!(defdisk->src = strdup(snapdisk->file))) {
+            if (VIR_STRDUP(defdisk->src, snapdisk->file) < 0) {
                 /* we cannot rollback here in a sane way */
                 virReportOOMError();
                 goto cleanup;
@@ -10870,9 +10870,9 @@ qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver,
     }
 
     if (virAsprintf(&device, "drive-%s", disk->info.alias) < 0 ||
-        !(source = strdup(snap->file)) ||
+        VIR_STRDUP(source, snap->file) < 0 ||
         (persistDisk &&
-         !(persistSource = strdup(source)))) {
+         VIR_STRDUP(persistSource, source) < 0)) {
         virReportOOMError();
         goto cleanup;
     }
@@ -10949,9 +10949,9 @@ qemuDomainSnapshotUndoSingleDiskActive(virQEMUDriverPtr driver,
     char *persistSource = NULL;
     struct stat st;
 
-    if (!(source = strdup(origdisk->src)) ||
+    if (VIR_STRDUP(source, origdisk->src) < 0 ||
         (persistDisk &&
-         !(persistSource = strdup(source)))) {
+         VIR_STRDUP(persistSource, source) < 0)) {
         virReportOOMError();
         goto cleanup;
     }
@@ -11558,12 +11558,10 @@ qemuDomainSnapshotCreateXML(virDomainPtr domain,
     if (update_current)
         snap->def->current = true;
     if (vm->current_snapshot) {
-        if (!(flags & VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE)) {
-            snap->def->parent = strdup(vm->current_snapshot->def->name);
-            if (snap->def->parent == NULL) {
-                virReportOOMError();
-                goto cleanup;
-            }
+        if (!(flags & VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE) &&
+            VIR_STRDUP(snap->def->parent, vm->current_snapshot->def->name) < 0) {
+            virReportOOMError();
+            goto cleanup;
         }
         if (update_current) {
             vm->current_snapshot->def->current = false;
@@ -12343,14 +12341,11 @@ qemuDomainSnapshotReparentChildren(void *payload,
     VIR_FREE(snap->def->parent);
     snap->parent = rep->parent;
 
-    if (rep->parent->def) {
-        snap->def->parent = strdup(rep->parent->def->name);
-
-        if (snap->def->parent == NULL) {
-            virReportOOMError();
-            rep->err = -1;
-            return;
-        }
+    if (rep->parent->def &&
+        VIR_STRDUP(snap->def->parent, rep->parent->def->name) < 0) {
+        virReportOOMError();
+        rep->err = -1;
+        return;
     }
 
     if (!snap->sibling)
@@ -13257,7 +13252,7 @@ qemuDomainBlockCopy(virDomainPtr dom, const char *path,
     }
     if (!format && disk->mirrorFormat > 0)
         format = virStorageFileFormatTypeToString(disk->mirrorFormat);
-    if (!(mirror = strdup(dest))) {
+    if (VIR_STRDUP(mirror, dest) < 0) {
         virReportOOMError();
         goto endjob;
     }
@@ -13891,7 +13886,7 @@ qemuDomainGetDiskErrors(virDomainPtr dom,
             if (n == nerrors)
                 break;
 
-            if (!(errors[n].disk = strdup(disk->dst))) {
+            if (VIR_STRDUP(errors[n].disk, disk->dst) < 0) {
                 virReportOOMError();
                 goto endjob;
             }
@@ -13951,14 +13946,12 @@ qemuDomainSetMetadata(virDomainPtr dom,
         switch ((virDomainMetadataType) type) {
         case VIR_DOMAIN_METADATA_DESCRIPTION:
             VIR_FREE(vm->def->description);
-            if (metadata &&
-                !(vm->def->description = strdup(metadata)))
+            if (metadata && VIR_STRDUP(vm->def->description, metadata) < 0)
                 goto no_memory;
             break;
         case VIR_DOMAIN_METADATA_TITLE:
             VIR_FREE(vm->def->title);
-            if (metadata &&
-                !(vm->def->title = strdup(metadata)))
+            if (metadata && VIR_STRDUP(vm->def->title, metadata) < 0)
                 goto no_memory;
             break;
         case VIR_DOMAIN_METADATA_ELEMENT:
@@ -13979,14 +13972,12 @@ qemuDomainSetMetadata(virDomainPtr dom,
         switch ((virDomainMetadataType) type) {
         case VIR_DOMAIN_METADATA_DESCRIPTION:
             VIR_FREE(persistentDef->description);
-            if (metadata &&
-                !(persistentDef->description = strdup(metadata)))
+            if (metadata && VIR_STRDUP(persistentDef->description, metadata) < 0)
                 goto no_memory;
             break;
         case VIR_DOMAIN_METADATA_TITLE:
             VIR_FREE(persistentDef->title);
-            if (metadata &&
-                !(persistentDef->title = strdup(metadata)))
+            if (metadata && VIR_STRDUP(persistentDef->title, metadata) < 0)
                 goto no_memory;
             break;
         case VIR_DOMAIN_METADATA_ELEMENT:
@@ -14073,7 +14064,7 @@ qemuDomainGetMetadata(virDomainPtr dom,
         goto cleanup;
     }
 
-    if (!(ret = strdup(field))) {
+    if (VIR_STRDUP(ret, field) < 0) {
         virReportOOMError();
         goto cleanup;
     }
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 24ff142..8416a25 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -1292,7 +1292,7 @@ qemuDomainNetGetBridgeName(virConnectPtr conn, virDomainNetDefPtr net)
             goto cleanup;
         }
         /* we need a copy, not just a pointer to the original */
-        if (!(brname = strdup(tmpbr))) {
+        if (VIR_STRDUP(brname, tmpbr) < 0) {
             virReportOOMError();
             goto cleanup;
         }
@@ -1548,8 +1548,7 @@ qemuDomainChangeNet(virQEMUDriverPtr driver,
     }
 
     /* ifname: check if it's set in newdev. If not, retain the autogenerated one */
-    if (!(newdev->ifname ||
-          (newdev->ifname = strdup(olddev->ifname)))) {
+    if (!newdev->ifname && VIR_STRDUP(newdev->ifname, olddev->ifname) < 0) {
         virReportOOMError();
         goto cleanup;
     }
@@ -1577,8 +1576,7 @@ qemuDomainChangeNet(virQEMUDriverPtr driver,
         goto cleanup;
     }
     /* grab alias from olddev if not set in newdev */
-    if (!(newdev->info.alias ||
-          (newdev->info.alias = strdup(olddev->info.alias)))) {
+    if (!newdev->info.alias && VIR_STRDUP(newdev->info.alias, olddev->info.alias) < 0) {
         virReportOOMError();
         goto cleanup;
     }
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 0732614..97639fd 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -316,7 +316,7 @@ qemuMigrationCookieGraphicsAlloc(virQEMUDriverPtr driver,
             goto error;
 #endif
     }
-    if (!(mig->listen = strdup(listenAddr)))
+    if (VIR_STRDUP(mig->listen, listenAddr) < 0)
         goto no_memory;
 
     virObjectUnref(cfg);
@@ -400,7 +400,7 @@ qemuMigrationCookieNew(virDomainObjPtr dom)
         name = priv->origname;
     else
         name = dom->def->name;
-    if (!(mig->name = strdup(name)))
+    if (VIR_STRDUP(mig->name, name) < 0)
         goto no_memory;
     memcpy(mig->uuid, dom->def->uuid, VIR_UUID_BUFLEN);
 
@@ -460,15 +460,14 @@ qemuMigrationCookieAddLockstate(qemuMigrationCookiePtr mig,
     }
 
     if (virDomainObjGetState(dom, NULL) == VIR_DOMAIN_PAUSED) {
-        if (priv->lockState &&
-            !(mig->lockState = strdup(priv->lockState)))
+        if (priv->lockState && VIR_STRDUP(mig->lockState, priv->lockState) < 0)
             return -1;
     } else {
         if (virDomainLockProcessInquire(driver->lockManager, dom, &mig->lockState) < 0)
             return -1;
     }
 
-    if (!(mig->lockDriver = strdup(virLockManagerPluginGetName(driver->lockManager)))) {
+    if (VIR_STRDUP(mig->lockDriver, virLockManagerPluginGetName(driver->lockManager)) < 0) {
         VIR_FREE(mig->lockState);
         return -1;
     }
@@ -2050,8 +2049,7 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver,
     /* Target domain name, maybe renamed. */
     if (dname) {
         origname = def->name;
-        def->name = strdup(dname);
-        if (def->name == NULL)
+        if (VIR_STRDUP(def->name, dname) < 0)
             goto cleanup;
     }
 
@@ -2101,7 +2099,7 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver,
         /* QEMU will be started with -incoming stdio
          * (which qemu_command might convert to exec:cat or fd:n)
          */
-        if (!(migrateFrom = strdup("stdio"))) {
+        if (VIR_STRDUP(migrateFrom, "stdio") < 0) {
             virReportOOMError();
             goto cleanup;
         }
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 6fdd650..37beea0 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -201,8 +201,9 @@ int qemuMonitorJSONIOProcess(qemuMonitorPtr mon,
 
         if (nl) {
             int got = nl - (data + used);
-            char *line = strndup(data + used, got);
-            if (!line) {
+            char *line;
+
+            if (VIR_STRNDUP(line, data + used, got) < 0) {
                 virReportOOMError();
                 return -1;
             }
@@ -956,14 +957,8 @@ qemuMonitorJSONHumanCommandWithFd(qemuMonitorPtr mon,
     }
 
     if (reply_str) {
-        const char *data;
-
-        if ((data = virJSONValueGetString(obj)))
-            *reply_str = strdup(data);
-        else
-            *reply_str = strdup("");
-
-        if (!*reply_str) {
+        const char *data = virJSONValueGetString(obj);
+        if (VIR_STRDUP(*reply_str, data ? data : "") < 0) {
             virReportOOMError();
             goto cleanup;
         }
@@ -2946,8 +2941,9 @@ static int qemuMonitorJSONExtractPtyPaths(virJSONValuePtr reply,
         }
 
         if (STRPREFIX(type, "pty:")) {
-            char *path = strdup(type + strlen("pty:"));
-            if (!path) {
+            char *path;
+
+            if (VIR_STRDUP(path, type + strlen("pty:")) < 0) {
                 virReportOOMError();
                 goto cleanup;
             }
@@ -3925,7 +3921,7 @@ int qemuMonitorJSONGetVersion(qemuMonitorPtr mon,
                            _("query-version reply was missing 'package' version"));
             goto cleanup;
         }
-        if (!(*package = strdup(tmp))) {
+        if (VIR_STRDUP(*package, tmp) < 0) {
             virReportOOMError();
             goto cleanup;
         }
@@ -4001,7 +3997,7 @@ int qemuMonitorJSONGetMachines(qemuMonitorPtr mon,
             goto cleanup;
         }
 
-        if (!(info->name = strdup(tmp))) {
+        if (VIR_STRDUP(info->name, tmp) < 0) {
             virReportOOMError();
             goto cleanup;
         }
@@ -4019,7 +4015,7 @@ int qemuMonitorJSONGetMachines(qemuMonitorPtr mon,
                                _("query-machines reply has malformed 'alias' data"));
                 goto cleanup;
             }
-            if (!(info->alias = strdup(tmp))) {
+            if (VIR_STRDUP(info->alias, tmp) < 0) {
                 virReportOOMError();
                 goto cleanup;
             }
@@ -4106,7 +4102,7 @@ int qemuMonitorJSONGetCPUDefinitions(qemuMonitorPtr mon,
             goto cleanup;
         }
 
-        if (!(cpulist[i] = strdup(tmp))) {
+        if (VIR_STRDUP(cpulist[i], tmp) < 0) {
             virReportOOMError();
             goto cleanup;
         }
@@ -4180,7 +4176,7 @@ int qemuMonitorJSONGetCommands(qemuMonitorPtr mon,
             goto cleanup;
         }
 
-        if (!(commandlist[i] = strdup(tmp))) {
+        if (VIR_STRDUP(commandlist[i], tmp) < 0) {
             virReportOOMError();
             goto cleanup;
         }
@@ -4259,7 +4255,7 @@ int qemuMonitorJSONGetEvents(qemuMonitorPtr mon,
             goto cleanup;
         }
 
-        if (!(eventlist[i] = strdup(tmp))) {
+        if (VIR_STRDUP(eventlist[i], tmp) < 0) {
             virReportOOMError();
             goto cleanup;
         }
@@ -4384,7 +4380,7 @@ int qemuMonitorJSONGetObjectTypes(qemuMonitorPtr mon,
             goto cleanup;
         }
 
-        if (!(typelist[i] = strdup(tmp))) {
+        if (VIR_STRDUP(typelist[i], tmp) < 0) {
             virReportOOMError();
             goto cleanup;
         }
@@ -4466,7 +4462,7 @@ int qemuMonitorJSONGetObjectProps(qemuMonitorPtr mon,
             goto cleanup;
         }
 
-        if (!(proplist[i] = strdup(tmp))) {
+        if (VIR_STRDUP(proplist[i], tmp) < 0) {
             virReportOOMError();
             goto cleanup;
         }
@@ -4520,7 +4516,7 @@ qemuMonitorJSONGetTargetArch(qemuMonitorPtr mon)
         goto cleanup;
     }
 
-    if (!(ret = strdup(arch))) {
+    if (VIR_STRDUP(ret, arch) < 0) {
         virReportOOMError();
         goto cleanup;
     }
@@ -4817,7 +4813,7 @@ qemuMonitorJSONGetStringArray(qemuMonitorPtr mon, const char *qmpCmd,
             goto cleanup;
         }
 
-        if (!(list[i] = strdup(tmp))) {
+        if (VIR_STRDUP(list[i], tmp) < 0) {
             virReportOOMError();
             goto cleanup;
         }
diff --git a/src/qemu/qemu_monitor_text.c b/src/qemu/qemu_monitor_text.c
index 696961b..eda9ed4 100644
--- a/src/qemu/qemu_monitor_text.c
+++ b/src/qemu/qemu_monitor_text.c
@@ -258,8 +258,7 @@ qemuMonitorTextCommandWithHandler(qemuMonitorPtr mon,
         if (msg.rxBuffer) {
             *reply = msg.rxBuffer;
         } else {
-            *reply = strdup("");
-            if (!*reply) {
+            if (VIR_STRDUP(*reply, "") < 0) {
                 virReportOOMError();
                 return -1;
             }
@@ -330,7 +329,7 @@ qemuMonitorSendDiskPassphrase(qemuMonitorPtr mon,
 
     /* Extra the path */
     pathStart += strlen(DISK_ENCRYPTION_PREFIX);
-    if (!(path = strndup(pathStart, pathEnd - pathStart))) {
+    if (VIR_STRNDUP(path, pathStart, pathEnd - pathStart) < 0) {
         virReportOOMError();
         return -1;
     }
@@ -2283,8 +2282,8 @@ int qemuMonitorTextGetPtyPaths(qemuMonitorPtr mon,
 
         /* Path is everything after needle to the end of the line */
         *eol = '\0';
-        char *path = strdup(needle + strlen(NEEDLE));
-        if (path == NULL) {
+        char *path;
+        if (VIR_STRDUP(path, needle + strlen(NEEDLE)) < 0) {
             virReportOOMError();
             goto cleanup;
         }
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 54a55b9..13371f3 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -1000,15 +1000,15 @@ qemuProcessHandleGraphics(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
     if (VIR_ALLOC(localAddr) < 0)
         goto no_memory;
     localAddr->family = localFamily;
-    if (!(localAddr->service = strdup(localService)) ||
-        !(localAddr->node = strdup(localNode)))
+    if (VIR_STRDUP(localAddr->service, localService) < 0 ||
+        VIR_STRDUP(localAddr->node, localNode) < 0)
         goto no_memory;
 
     if (VIR_ALLOC(remoteAddr) < 0)
         goto no_memory;
     remoteAddr->family = remoteFamily;
-    if (!(remoteAddr->service = strdup(remoteService)) ||
-        !(remoteAddr->node = strdup(remoteNode)))
+    if (VIR_STRDUP(remoteAddr->service, remoteService) < 0 ||
+        VIR_STRDUP(remoteAddr->node, remoteNode) < 0)
         goto no_memory;
 
     if (VIR_ALLOC(subject) < 0)
@@ -1017,16 +1017,16 @@ qemuProcessHandleGraphics(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
         if (VIR_REALLOC_N(subject->identities, subject->nidentity+1) < 0)
             goto no_memory;
         subject->nidentity++;
-        if (!(subject->identities[subject->nidentity-1].type = strdup("x509dname")) ||
-            !(subject->identities[subject->nidentity-1].name = strdup(x509dname)))
+        if (VIR_STRDUP(subject->identities[subject->nidentity-1].type, "x509dname") < 0 ||
+            VIR_STRDUP(subject->identities[subject->nidentity-1].name, x509dname) < 0)
             goto no_memory;
     }
     if (saslUsername) {
         if (VIR_REALLOC_N(subject->identities, subject->nidentity+1) < 0)
             goto no_memory;
         subject->nidentity++;
-        if (!(subject->identities[subject->nidentity-1].type = strdup("saslUsername")) ||
-            !(subject->identities[subject->nidentity-1].name = strdup(saslUsername)))
+        if (VIR_STRDUP(subject->identities[subject->nidentity-1].type, "saslUsername") < 0 ||
+            VIR_STRDUP(subject->identities[subject->nidentity-1].name, saslUsername) < 0)
             goto no_memory;
     }
 
@@ -1480,8 +1480,7 @@ qemuProcessExtractTTYPath(const char *haystack,
      */
     while (*tmp) {
         if (c_isspace(*tmp)) {
-            *path = strndup(dev, tmp-dev);
-            if (*path == NULL) {
+            if (VIR_STRNDUP(*path, dev, tmp-dev) < 0) {
                 virReportOOMError();
                 return -1;
             }
@@ -1539,9 +1538,7 @@ qemuProcessLookupPTYs(virDomainChrDefPtr *devices,
             }
 
             VIR_FREE(chr->source.data.file.path);
-            chr->source.data.file.path = strdup(path);
-
-            if (chr->source.data.file.path == NULL) {
+            if (VIR_STRDUP(chr->source.data.file.path, path) < 0) {
                 virReportOOMError();
                 return -1;
             }
@@ -2666,12 +2663,18 @@ qemuProcessUpdateState(virQEMUDriverPtr driver, virDomainObjPtr vm)
     if (state == VIR_DOMAIN_PAUSED && running) {
         newState = VIR_DOMAIN_RUNNING;
         newReason = VIR_DOMAIN_RUNNING_UNPAUSED;
-        msg = strdup("was unpaused");
+        if (VIR_STRDUP(msg, "was unpaused") < 0) {
+            virReportOOMError();
+            return -1;
+        }
     } else if (state == VIR_DOMAIN_RUNNING && !running) {
         if (reason == VIR_DOMAIN_PAUSED_SHUTTING_DOWN) {
             newState = VIR_DOMAIN_SHUTDOWN;
             newReason = VIR_DOMAIN_SHUTDOWN_UNKNOWN;
-            msg = strdup("shutdown");
+            if (VIR_STRDUP(msg, "shutdown") < 0) {
+                virReportOOMError();
+                return -1;
+            }
         } else {
             newState = VIR_DOMAIN_PAUSED;
             newReason = reason;
@@ -2681,15 +2684,13 @@ qemuProcessUpdateState(virQEMUDriverPtr driver, virDomainObjPtr vm)
     } else if (state == VIR_DOMAIN_SHUTOFF && running) {
         newState = VIR_DOMAIN_RUNNING;
         newReason = VIR_DOMAIN_RUNNING_BOOTED;
-        msg = strdup("finished booting");
-    }
-
-    if (newState != VIR_DOMAIN_NOSTATE) {
-        if (!msg) {
+        if (VIR_STRDUP(msg, "finished booting") < 0) {
             virReportOOMError();
             return -1;
         }
+    }
 
+    if (newState != VIR_DOMAIN_NOSTATE) {
         VIR_DEBUG("Domain %s %s while its monitor was disconnected;"
                   " changing state to %s (%s)",
                   vm->def->name,
@@ -3462,11 +3463,9 @@ int qemuProcessStart(virConnectPtr conn,
                     goto cleanup;
                 }
                 graphics->listens[0].type = VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS;
-                if (graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC)
-                    graphics->listens[0].address = strdup(cfg->vncListen);
-                else
-                    graphics->listens[0].address = strdup(cfg->spiceListen);
-                if (!graphics->listens[0].address) {
+                if (VIR_STRDUP(graphics->listens[0].address,
+                               graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC ?
+                               cfg->vncListen : cfg->spiceListen) < 0) {
                     VIR_SHRINK_N(graphics->listens, graphics->nListens, 1);
                     virReportOOMError();
                     goto cleanup;
@@ -4234,8 +4233,7 @@ int qemuProcessAttach(virConnectPtr conn ATTRIBUTE_UNUSED,
     }
 
     VIR_FREE(priv->pidfile);
-    if (pidfile &&
-        !(priv->pidfile = strdup(pidfile)))
+    if (pidfile && VIR_STRDUP(priv->pidfile, pidfile) < 0)
         goto no_memory;
 
     VIR_DEBUG("Detect security driver config");
@@ -4257,10 +4255,10 @@ int qemuProcessAttach(virConnectPtr conn ATTRIBUTE_UNUSED,
                                               vm->def, vm->pid, seclabel) < 0)
             goto cleanup;
 
-        if (!(seclabeldef->model = strdup(model)))
+        if (VIR_STRDUP(seclabeldef->model, model) < 0)
             goto no_memory;
 
-        if (!(seclabeldef->label = strdup(seclabel->label)))
+        if (VIR_STRDUP(seclabeldef->label, seclabel->label) < 0)
             goto no_memory;
         VIR_FREE(seclabel);
     }
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index 13212d0..97be2a0 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -3733,7 +3733,7 @@ static int remoteAuthMakeCredentials(sasl_interact_t *interact,
         }
         if (interact[*ncred].challenge)
             (*cred)[*ncred].challenge = interact[ninteract].challenge;
-        (*cred)[*ncred].prompt = interact[ninteract].prompt;
+        (*cred)[*ncred].prompt = (char *) interact[ninteract].prompt;
         if (interact[*ncred].defresult)
             (*cred)[*ncred].defresult = interact[ninteract].defresult;
         (*cred)[*ncred].result = NULL;
-- 
1.8.1.5


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