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

[libvirt] [PATCH v2 26/37] Adapt to VIR_STRDUP in src/util/*



---
 src/util/virauth.c               |   8 +-
 src/util/virauthconfig.c         |   4 +-
 src/util/virbitmap.c             |   9 ++-
 src/util/vircgroup.c             |  31 +++-----
 src/util/vircommand.c            |  29 +++----
 src/util/virconf.c               |  21 ++---
 src/util/virdnsmasq.c            |   4 +-
 src/util/virebtables.c           |  34 ++++----
 src/util/virerror.c              |  18 ++---
 src/util/virhash.c               |   5 +-
 src/util/viridentity.c           |   9 ++-
 src/util/virinitctl.c            |   2 +-
 src/util/viriptables.c           |   4 +-
 src/util/virjson.c               |  17 ++--
 src/util/virkeyfile.c            |   7 +-
 src/util/virlockspace.c          |  13 ++-
 src/util/virlog.c                |  18 ++---
 src/util/virnetdevmacvlan.c      |   9 ++-
 src/util/virnetdevtap.c          |   5 +-
 src/util/virnetdevvportprofile.c |   3 +-
 src/util/virobject.c             |   5 +-
 src/util/virpci.c                |   5 +-
 src/util/virsexpr.c              |  25 ++----
 src/util/virsocketaddr.c         |   4 +-
 src/util/virstoragefile.c        |  11 +--
 src/util/virstring.c             |   6 +-
 src/util/virsysinfo.c            | 168 ++++++++++++++++-----------------------
 src/util/virtypedparam.c         |   8 +-
 src/util/viruri.c                |  18 ++---
 src/util/virutil.c               |  59 +++++++-------
 src/util/virxml.c                |   6 +-
 31 files changed, 252 insertions(+), 313 deletions(-)

diff --git a/src/util/virauth.c b/src/util/virauth.c
index fdcefe1..fcd4d3a 100644
--- a/src/util/virauth.c
+++ b/src/util/virauth.c
@@ -51,7 +51,7 @@ int virAuthGetConfigFilePath(virConnectPtr conn,
 
     if (authenv) {
         VIR_DEBUG("Using path from env '%s'", authenv);
-        if (!(*path = strdup(authenv)))
+        if (VIR_STRDUP(*path, authenv) < 0)
             goto no_memory;
         return 0;
     }
@@ -62,7 +62,7 @@ int virAuthGetConfigFilePath(virConnectPtr conn,
                 conn->uri->params[i].value) {
                 VIR_DEBUG("Using path from URI '%s'",
                           conn->uri->params[i].value);
-                if (!(*path = strdup(conn->uri->params[i].value)))
+                if (VIR_STRDUP(*path, conn->uri->params[i].value) < 0)
                     goto no_memory;
                 return 0;
             }
@@ -81,7 +81,7 @@ int virAuthGetConfigFilePath(virConnectPtr conn,
 
     VIR_FREE(*path);
 
-    if (!(*path = strdup(SYSCONFDIR "/libvirt/auth.conf")))
+    if (VIR_STRDUP(*path, SYSCONFDIR "/libvirt/auth.conf") < 0)
         goto no_memory;
 
     VIR_DEBUG("Checking for readability of '%s'", *path);
@@ -137,7 +137,7 @@ virAuthGetCredential(virConnectPtr conn,
         goto cleanup;
 
     if (tmp &&
-        !(*value = strdup(tmp))) {
+        VIR_STRDUP(*value, tmp) < 0) {
         virReportOOMError();
         goto cleanup;
     }
diff --git a/src/util/virauthconfig.c b/src/util/virauthconfig.c
index 4259cb3..978be5d 100644
--- a/src/util/virauthconfig.c
+++ b/src/util/virauthconfig.c
@@ -47,7 +47,7 @@ virAuthConfigPtr virAuthConfigNew(const char *path)
         goto error;
     }
 
-    if (!(auth->path = strdup(path))) {
+    if (VIR_STRDUP(auth->path, path) < 0) {
         virReportOOMError();
         goto error;
     }
@@ -77,7 +77,7 @@ virAuthConfigPtr virAuthConfigNewData(const char *path,
         goto error;
     }
 
-    if (!(auth->path = strdup(path))) {
+    if (VIR_STRDUP(auth->path, path) < 0) {
         virReportOOMError();
         goto error;
     }
diff --git a/src/util/virbitmap.c b/src/util/virbitmap.c
index c81555a..cf6a099 100644
--- a/src/util/virbitmap.c
+++ b/src/util/virbitmap.c
@@ -37,6 +37,8 @@
 #include "count-one-bits.h"
 #include "virstring.h"
 
+#define VIR_FROM_THIS VIR_FROM_NONE
+
 struct _virBitmap {
     size_t max_bit;
     size_t map_len;
@@ -226,8 +228,11 @@ char *virBitmapFormat(virBitmapPtr bitmap)
         return NULL;
 
     cur = virBitmapNextSetBit(bitmap, -1);
-    if (cur < 0)
-        return strdup("");
+    if (cur < 0) {
+        char *ret;
+        ignore_value(VIR_STRDUP(ret, ""));
+        return ret;
+    }
 
     start = prev = cur;
     while (prev >= 0) {
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index b05fc45..bf54b2a 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -116,19 +116,14 @@ static int virCgroupCopyMounts(virCgroupPtr group,
         if (!parent->controllers[i].mountPoint)
             continue;
 
-        group->controllers[i].mountPoint =
-            strdup(parent->controllers[i].mountPoint);
-
-        if (!group->controllers[i].mountPoint)
+        if (VIR_STRDUP(group->controllers[i].mountPoint,
+                       parent->controllers[i].mountPoint) < 0)
             return -ENOMEM;
 
-        if (parent->controllers[i].linkPoint) {
-            group->controllers[i].linkPoint =
-                strdup(parent->controllers[i].linkPoint);
-
-            if (!group->controllers[i].linkPoint)
-                return -ENOMEM;
-        }
+        if (parent->controllers[i].linkPoint &&
+            VIR_STRDUP(group->controllers[i].linkPoint,
+                       parent->controllers[i].linkPoint) < 0)
+            return -ENOMEM;
     }
     return 0;
 }
@@ -177,7 +172,7 @@ static int virCgroupDetectMounts(virCgroupPtr group)
                     struct stat sb;
                     char *tmp2;
 
-                    if (!(group->controllers[i].mountPoint = strdup(entry.mnt_dir)))
+                    if (VIR_STRDUP(group->controllers[i].mountPoint, entry.mnt_dir) < 0)
                         goto no_memory;
 
                     tmp2 = strrchr(entry.mnt_dir, '/');
@@ -239,7 +234,7 @@ static int virCgroupCopyPlacement(virCgroupPtr group,
             continue;
 
         if (path[0] == '/') {
-            if (!(group->controllers[i].placement = strdup(path)))
+            if (VIR_STRDUP(group->controllers[i].placement, path) < 0)
                 return -ENOMEM;
         } else {
             /*
@@ -821,7 +816,7 @@ static int virCgroupNew(const char *path,
     }
 
     if (path[0] == '/' || !parent) {
-        if (!((*group)->path = strdup(path))) {
+        if (VIR_STRDUP((*group)->path, path) < 0) {
             rc = -ENOMEM;
             goto err;
         }
@@ -1253,7 +1248,7 @@ int virCgroupNewPartition(const char *path,
 
     if (STRNEQ(newpath, "/")) {
         char *tmp;
-        if (!(parentPath = strdup(newpath))) {
+        if (VIR_STRDUP(parentPath, newpath) < 0) {
             rc = -ENOMEM;
             goto cleanup;
         }
@@ -2543,12 +2538,12 @@ static char *virCgroupIdentifyRoot(virCgroupPtr group)
         }
 
         tmp[0] = '\0';
-        ret = strdup(group->controllers[i].mountPoint);
-        tmp[0] = '/';
-        if (!ret) {
+        if (VIR_STRDUP(ret, group->controllers[i].mountPoint) < 0) {
+            tmp[0] = '/';
             virReportOOMError();
             return NULL;
         }
+        tmp[0] = '/';
         return ret;
     }
 
diff --git a/src/util/vircommand.c b/src/util/vircommand.c
index f6f27d9..460e25b 100644
--- a/src/util/vircommand.c
+++ b/src/util/vircommand.c
@@ -946,7 +946,7 @@ virCommandSetPidFile(virCommandPtr cmd, const char *pidfile)
         return;
 
     VIR_FREE(cmd->pidfile);
-    if (!(cmd->pidfile = strdup(pidfile))) {
+    if (VIR_STRDUP(cmd->pidfile, pidfile) < 0) {
         cmd->has_error = ENOMEM;
     }
 }
@@ -1049,7 +1049,7 @@ virCommandSetSELinuxLabel(virCommandPtr cmd,
 
 #if defined(WITH_SECDRIVER_SELINUX)
     VIR_FREE(cmd->seLinuxLabel);
-    if (label && !(cmd->seLinuxLabel = strdup(label)))
+    if (label && VIR_STRDUP(cmd->seLinuxLabel, label) < 0)
         cmd->has_error = ENOMEM;
 #endif
     return;
@@ -1074,7 +1074,7 @@ virCommandSetAppArmorProfile(virCommandPtr cmd,
 
 #if defined(WITH_SECDRIVER_APPARMOR)
     VIR_FREE(cmd->appArmorProfile);
-    if (profile && !(cmd->appArmorProfile = strdup(profile)))
+    if (profile && VIR_STRDUP(cmd->appArmorProfile, profile) < 0)
         cmd->has_error = ENOMEM;
 #endif
     return;
@@ -1205,7 +1205,7 @@ virCommandAddEnvString(virCommandPtr cmd, const char *str)
     if (!cmd || cmd->has_error)
         return;
 
-    if (!(env = strdup(str))) {
+    if (VIR_STRDUP(env, str) < 0) {
         cmd->has_error = ENOMEM;
         return;
     }
@@ -1309,7 +1309,7 @@ virCommandAddArg(virCommandPtr cmd, const char *val)
     if (!cmd || cmd->has_error)
         return;
 
-    if (!(arg = strdup(val))) {
+    if (VIR_STRDUP(arg, val) < 0) {
         cmd->has_error = ENOMEM;
         return;
     }
@@ -1350,9 +1350,8 @@ virCommandAddArgBuffer(virCommandPtr cmd, virBufferPtr buf)
     }
 
     cmd->args[cmd->nargs] = virBufferContentAndReset(buf);
-    if (!cmd->args[cmd->nargs])
-        cmd->args[cmd->nargs] = strdup("");
-    if (!cmd->args[cmd->nargs]) {
+    if (!cmd->args[cmd->nargs] &&
+        VIR_STRDUP(cmd->args[cmd->nargs], "") < 0) {
         cmd->has_error = ENOMEM;
         return;
     }
@@ -1440,8 +1439,9 @@ virCommandAddArgSet(virCommandPtr cmd, const char *const*vals)
 
     narg = 0;
     while (vals[narg] != NULL) {
-        char *arg = strdup(vals[narg++]);
-        if (!arg) {
+        char *arg;
+
+        if (VIR_STRDUP(arg, vals[narg++]) < 0) {
             cmd->has_error = ENOMEM;
             return;
         }
@@ -1481,8 +1481,7 @@ virCommandAddArgList(virCommandPtr cmd, ...)
         char *arg = va_arg(list, char *);
         if (!arg)
             break;
-        arg = strdup(arg);
-        if (!arg) {
+        if (VIR_STRDUP(arg, arg) < 0) {
             cmd->has_error = ENOMEM;
             va_end(list);
             return;
@@ -1511,8 +1510,7 @@ virCommandSetWorkingDirectory(virCommandPtr cmd, const char *pwd)
         cmd->has_error = -1;
         VIR_DEBUG("cannot set directory twice");
     } else {
-        cmd->pwd = strdup(pwd);
-        if (!cmd->pwd)
+        if (VIR_STRDUP(cmd->pwd, pwd) < 0)
             cmd->has_error = ENOMEM;
     }
 }
@@ -1539,8 +1537,7 @@ virCommandSetInputBuffer(virCommandPtr cmd, const char *inbuf)
         return;
     }
 
-    cmd->inbuf = strdup(inbuf);
-    if (!cmd->inbuf)
+    if (VIR_STRDUP(cmd->inbuf, inbuf) < 0)
         cmd->has_error = ENOMEM;
 }
 
diff --git a/src/util/virconf.c b/src/util/virconf.c
index 16f074a..cd5f47c 100644
--- a/src/util/virconf.c
+++ b/src/util/virconf.c
@@ -38,6 +38,7 @@
 #include "virlog.h"
 #include "viralloc.h"
 #include "virfile.h"
+#include "virstring.h"
 
 #define VIR_FROM_THIS VIR_FROM_CONF
 
@@ -397,8 +398,7 @@ virConfParseString(virConfParserCtxtPtr ctxt)
             virConfError(ctxt, VIR_ERR_CONF_SYNTAX, _("unterminated string"));
             return NULL;
         }
-        ret = strndup(base, ctxt->cur - base);
-        if (ret == NULL) {
+        if (VIR_STRNDUP(ret, base, ctxt->cur - base) < 0) {
             virReportOOMError();
             return NULL;
         }
@@ -421,8 +421,7 @@ virConfParseString(virConfParserCtxtPtr ctxt)
             virConfError(ctxt, VIR_ERR_CONF_SYNTAX, _("unterminated string"));
             return NULL;
         }
-        ret = strndup(base, ctxt->cur - base);
-        if (ret == NULL) {
+        if (VIR_STRNDUP(ret, base, ctxt->cur - base) < 0) {
             virReportOOMError();
             return NULL;
         }
@@ -436,8 +435,7 @@ virConfParseString(virConfParserCtxtPtr ctxt)
             virConfError(ctxt, VIR_ERR_CONF_SYNTAX, _("unterminated string"));
             return NULL;
         }
-        ret = strndup(base, ctxt->cur - base);
-        if (ret == NULL) {
+        if (VIR_STRNDUP(ret, base, ctxt->cur - base) < 0) {
             virReportOOMError();
             return NULL;
         }
@@ -577,8 +575,7 @@ virConfParseName(virConfParserCtxtPtr ctxt)
             ((ctxt->conf->flags & VIR_CONF_FLAG_VMX_FORMAT) &&
              ((CUR == ':') || (CUR == '.') || (CUR == '-')))))
         NEXT;
-    ret = strndup(base, ctxt->cur - base);
-    if (ret == NULL) {
+    if (VIR_STRNDUP(ret, base, ctxt->cur - base) < 0) {
         virReportOOMError();
         return NULL;
     }
@@ -604,8 +601,7 @@ virConfParseComment(virConfParserCtxtPtr ctxt)
     NEXT;
     base = ctxt->cur;
     while ((ctxt->cur < ctxt->end) && (!IS_EOL(CUR))) NEXT;
-    comm = strndup(base, ctxt->cur - base);
-    if (comm == NULL) {
+    if (VIR_STRNDUP(comm, base, ctxt->cur - base) < 0) {
         virReportOOMError();
         return -1;
     }
@@ -680,8 +676,7 @@ virConfParseStatement(virConfParserCtxtPtr ctxt)
         NEXT;
         base = ctxt->cur;
         while ((ctxt->cur < ctxt->end) && (!IS_EOL(CUR))) NEXT;
-        comm = strndup(base, ctxt->cur - base);
-        if (comm == NULL) {
+        if (VIR_STRNDUP(comm, base, ctxt->cur - base) < 0) {
             virReportOOMError();
             VIR_FREE(name);
             virConfFreeValue(value);
@@ -905,7 +900,7 @@ virConfSetValue(virConfPtr conf,
             return -1;
         }
         cur->comment = NULL;
-        if (!(cur->name = strdup(setting))) {
+        if (VIR_STRDUP(cur->name, setting) < 0) {
             virReportOOMError();
             virConfFreeValue(value);
             VIR_FREE(cur);
diff --git a/src/util/virdnsmasq.c b/src/util/virdnsmasq.c
index 4f05633..b162650 100644
--- a/src/util/virdnsmasq.c
+++ b/src/util/virdnsmasq.c
@@ -469,7 +469,7 @@ dnsmasqContextNew(const char *network_name,
         return NULL;
     }
 
-    if (!(ctx->config_dir = strdup(config_dir))) {
+    if (VIR_STRDUP(ctx->config_dir, config_dir) < 0) {
         virReportOOMError();
         goto error;
     }
@@ -798,7 +798,7 @@ dnsmasqCapsNewEmpty(const char *binaryPath)
         return NULL;
     if (!(caps->flags = virBitmapNew(DNSMASQ_CAPS_LAST)))
         goto error;
-    if (!(caps->binaryPath = strdup(binaryPath ? binaryPath : DNSMASQ)))
+    if (VIR_STRDUP(caps->binaryPath, binaryPath ? binaryPath : DNSMASQ) < 0)
         goto error;
     return caps;
 
diff --git a/src/util/virebtables.c b/src/util/virebtables.c
index 6bc6fed..13c462c 100644
--- a/src/util/virebtables.c
+++ b/src/util/virebtables.c
@@ -51,6 +51,8 @@
 #include "virstring.h"
 #include "virutil.h"
 
+#define VIR_FROM_THIS VIR_FROM_NONE
+
 #if HAVE_FIREWALLD
 static char *firewall_cmd_path = NULL;
 
@@ -186,10 +188,10 @@ ebtRulesNew(const char *table,
     if (VIR_ALLOC(rules) < 0)
         return NULL;
 
-    if (!(rules->table = strdup(table)))
+    if (VIR_STRDUP(rules->table, table) < 0)
         goto error;
 
-    if (!(rules->chain = strdup(chain)))
+    if (VIR_STRDUP(rules->chain, chain) < 0)
         goto error;
 
     rules->rules = NULL;
@@ -207,7 +209,7 @@ ebtablesAddRemoveRule(ebtRules *rules, int action, const char *arg, ...)
 {
     va_list args;
     int retval = ENOMEM;
-    const char **argv;
+    char **argv;
     char *rule = NULL;
     const char *s;
     int n, command_idx;
@@ -236,36 +238,36 @@ ebtablesAddRemoveRule(ebtRules *rules, int action, const char *arg, ...)
 
 #if HAVE_FIREWALLD
     if (firewall_cmd_path) {
-        if (!(argv[n++] = strdup(firewall_cmd_path)))
+        if (VIR_STRDUP(argv[n++], firewall_cmd_path) < 0)
             goto error;
-        if (!(argv[n++] = strdup("--direct")))
+        if (VIR_STRDUP(argv[n++], "--direct") < 0)
             goto error;
-        if (!(argv[n++] = strdup("--passthrough")))
+        if (VIR_STRDUP(argv[n++], "--passthrough") < 0)
             goto error;
-        if (!(argv[n++] = strdup("eb")))
+        if (VIR_STRDUP(argv[n++], "eb") < 0)
             goto error;
     } else
 #endif
-    if (!(argv[n++] = strdup(EBTABLES_PATH)))
+    if (VIR_STRDUP(argv[n++], EBTABLES_PATH) < 0)
         goto error;
 
     command_idx = n;
 
     if (action == ADD || action == REMOVE) {
-        if (!(argv[n++] = strdup("--insert")))
+        if (VIR_STRDUP(argv[n++], "--insert") < 0)
             goto error;
 
-        if (!(argv[n++] = strdup(rules->chain)))
+        if (VIR_STRDUP(argv[n++], rules->chain) < 0)
             goto error;
     }
 
-    if (!(argv[n++] = strdup(arg)))
+    if (VIR_STRDUP(argv[n++], arg) < 0)
         goto error;
 
     va_start(args, arg);
 
     while ((s = va_arg(args, const char *))) {
-        if (!(argv[n++] = strdup(s))) {
+        if (VIR_STRDUP(argv[n++], s) < 0) {
             va_end(args);
             goto error;
         }
@@ -273,23 +275,23 @@ ebtablesAddRemoveRule(ebtRules *rules, int action, const char *arg, ...)
 
     va_end(args);
 
-    if (!(rule = virArgvToString(&argv[command_idx])))
+    if (!(rule = virArgvToString((const char * const *) &argv[command_idx])))
         goto error;
 
     if (action == REMOVE) {
         VIR_FREE(argv[command_idx]);
-        if (!(argv[command_idx] = strdup("--delete")))
+        if (VIR_STRDUP(argv[command_idx], "--delete") < 0)
             goto error;
     }
 
-    if (virRun(argv, NULL) < 0) {
+    if (virRun((const char * const *) argv, NULL) < 0) {
         retval = errno;
         goto error;
     }
 
     if (action == ADD || action == CREATE || action == POLICY ||
         action == INSERT) {
-        retval = ebtRulesAppend(rules, rule, argv, command_idx);
+        retval = ebtRulesAppend(rules, rule, (const char **) argv, command_idx);
         rule = NULL;
         argv = NULL;
     } else {
diff --git a/src/util/virerror.c b/src/util/virerror.c
index af4da8c..8761a72 100644
--- a/src/util/virerror.c
+++ b/src/util/virerror.c
@@ -164,7 +164,7 @@ virErrorGenericFailure(virErrorPtr err)
     err->code = VIR_ERR_INTERNAL_ERROR;
     err->domain = VIR_FROM_NONE;
     err->level = VIR_ERR_ERROR;
-    err->message = strdup(_("An error occurred, but the cause is unknown"));
+    ignore_value(VIR_STRDUP_QUIET(err->message, _("An error occurred, but the cause is unknown")));
 }
 
 
@@ -184,13 +184,13 @@ virCopyError(virErrorPtr from,
     to->code = from->code;
     to->domain = from->domain;
     to->level = from->level;
-    if (from->message && !(to->message = strdup(from->message)))
+    if (from->message && VIR_STRDUP_QUIET(to->message, from->message) < 0)
         ret = -1;
-    if (from->str1 && !(to->str1 = strdup(from->str1)))
+    if (from->str1 && VIR_STRDUP_QUIET(to->str1, from->str1) < 0)
         ret = -1;
-    if (from->str2 && !(to->str2 = strdup(from->str2)))
+    if (from->str2 && VIR_STRDUP_QUIET(to->str2, from->str2) < 0)
         ret = -1;
-    if (from->str3 && !(to->str3 = strdup(from->str3)))
+    if (from->str3 && VIR_STRDUP_QUIET(to->str3, from->str3) < 0)
         ret = -1;
     to->int1 = from->int1;
     to->int2 = from->int2;
@@ -646,7 +646,7 @@ virRaiseErrorFull(const char *filename ATTRIBUTE_UNUSED,
      * formats the message; drop message on OOM situations
      */
     if (fmt == NULL) {
-        str = strdup(_("No error message provided"));
+        ignore_value(VIR_STRDUP_QUIET(str, _("No error message provided")));
     } else {
         va_list ap;
         va_start(ap, fmt);
@@ -666,11 +666,11 @@ virRaiseErrorFull(const char *filename ATTRIBUTE_UNUSED,
     to->message = str;
     to->level = level;
     if (str1 != NULL)
-        to->str1 = strdup(str1);
+        ignore_value(VIR_STRDUP_QUIET(to->str1, str1));
     if (str2 != NULL)
-        to->str2 = strdup(str2);
+        ignore_value(VIR_STRDUP_QUIET(to->str2, str2));
     if (str3 != NULL)
-        to->str3 = strdup(str3);
+        ignore_value(VIR_STRDUP_QUIET(to->str3, str3));
     to->int1 = int1;
     to->int2 = int2;
 
diff --git a/src/util/virhash.c b/src/util/virhash.c
index 2fe8751..bb708fc 100644
--- a/src/util/virhash.c
+++ b/src/util/virhash.c
@@ -30,6 +30,7 @@
 #include "virlog.h"
 #include "virhashcode.h"
 #include "virrandom.h"
+#include "virstring.h"
 
 #define VIR_FROM_THIS VIR_FROM_NONE
 
@@ -85,7 +86,9 @@ static bool virHashStrEqual(const void *namea, const void *nameb)
 
 static void *virHashStrCopy(const void *name)
 {
-    return strdup(name);
+    char *ret;
+    ignore_value(VIR_STRDUP(ret, name));
+    return ret;
 }
 
 static void virHashStrFree(void *name)
diff --git a/src/util/viridentity.c b/src/util/viridentity.c
index c9efd3f..864c75a 100644
--- a/src/util/viridentity.c
+++ b/src/util/viridentity.c
@@ -34,6 +34,7 @@
 #include "virobject.h"
 #include "virthread.h"
 #include "virutil.h"
+#include "virstring.h"
 
 #define VIR_FROM_THIS VIR_FROM_IDENTITY
 
@@ -150,12 +151,12 @@ virIdentityPtr virIdentityGetSystem(void)
                              _("Unable to lookup SELinux process context"));
         goto cleanup;
     }
-    seccontext = strdup(con);
-    freecon(con);
-    if (!seccontext) {
+    if (VIR_STRDUP(seccontext, con) < 0) {
+        freecon(con);
         virReportOOMError();
         goto cleanup;
     }
+    freecon(con);
 #endif
 
     if (!(ret = virIdentityNew()))
@@ -246,7 +247,7 @@ int virIdentitySetAttr(virIdentityPtr ident,
         goto cleanup;
     }
 
-    if (!(ident->attrs[attr] = strdup(value))) {
+    if (VIR_STRDUP(ident->attrs[attr], value) < 0) {
         virReportOOMError();
         goto cleanup;
     }
diff --git a/src/util/virinitctl.c b/src/util/virinitctl.c
index 3322454..b9a7fbf 100644
--- a/src/util/virinitctl.c
+++ b/src/util/virinitctl.c
@@ -133,7 +133,7 @@ int virInitctlSetRunLevel(virInitctlRunLevel level,
             return -1;
         }
     } else {
-        if (!(path = strdup(VIR_INITCTL_FIFO))) {
+        if (VIR_STRDUP(path, VIR_INITCTL_FIFO) < 0) {
             virReportOOMError();
             return -1;
         }
diff --git a/src/util/viriptables.c b/src/util/viriptables.c
index 06a1356..88c3bcd 100644
--- a/src/util/viriptables.c
+++ b/src/util/viriptables.c
@@ -118,10 +118,10 @@ iptRulesNew(const char *table,
     if (VIR_ALLOC(rules) < 0)
         return NULL;
 
-    if (!(rules->table = strdup(table)))
+    if (VIR_STRDUP(rules->table, table) < 0)
         goto error;
 
-    if (!(rules->chain = strdup(chain)))
+    if (VIR_STRDUP(rules->chain, chain) < 0)
         goto error;
 
     return rules;
diff --git a/src/util/virjson.c b/src/util/virjson.c
index 92138d3..995af90 100644
--- a/src/util/virjson.c
+++ b/src/util/virjson.c
@@ -107,7 +107,7 @@ virJSONValuePtr virJSONValueNewString(const char *data)
         return NULL;
 
     val->type = VIR_JSON_TYPE_STRING;
-    if (!(val->data.string = strdup(data))) {
+    if (VIR_STRDUP(val->data.string, data) < 0) {
         VIR_FREE(val);
         return NULL;
     }
@@ -126,7 +126,7 @@ virJSONValuePtr virJSONValueNewStringLen(const char *data, size_t length)
         return NULL;
 
     val->type = VIR_JSON_TYPE_STRING;
-    if (!(val->data.string = strndup(data, length))) {
+    if (VIR_STRNDUP(val->data.string, data, length) < 0) {
         VIR_FREE(val);
         return NULL;
     }
@@ -142,7 +142,7 @@ static virJSONValuePtr virJSONValueNewNumber(const char *data)
         return NULL;
 
     val->type = VIR_JSON_TYPE_NUMBER;
-    if (!(val->data.number = strdup(data))) {
+    if (VIR_STRDUP(val->data.number, data) < 0) {
         VIR_FREE(val);
         return NULL;
     }
@@ -269,7 +269,7 @@ int virJSONValueObjectAppend(virJSONValuePtr object, const char *key, virJSONVal
     if (virJSONValueObjectHasKey(object, key))
         return -1;
 
-    if (!(newkey = strdup(key)))
+    if (VIR_STRDUP(newkey, key) < 0)
         return -1;
 
     if (VIR_REALLOC_N(object->data.object.pairs,
@@ -751,10 +751,10 @@ static int virJSONParserHandleNumber(void *ctx,
                                      yajl_size_t l)
 {
     virJSONParserPtr parser = ctx;
-    char *str = strndup(s, l);
+    char *str;
     virJSONValuePtr value;
 
-    if (!str)
+    if (VIR_STRNDUP(str, s, l) < 0)
         return -1;
     value = virJSONValueNewNumber(str);
     VIR_FREE(str);
@@ -808,8 +808,7 @@ static int virJSONParserHandleMapKey(void *ctx,
     state = &parser->state[parser->nstate-1];
     if (state->key)
         return 0;
-    state->key = strndup((const char *)stringVal, stringLen);
-    if (!state->key)
+    if (VIR_STRNDUP(state->key, (const char *)stringVal, stringLen) < 0)
         return 0;
     return 1;
 }
@@ -1094,7 +1093,7 @@ char *virJSONValueToString(virJSONValuePtr object,
         goto cleanup;
     }
 
-    if (!(ret = strdup((const char *)str)))
+    if (VIR_STRDUP(ret, (const char *)str) < 0)
         virReportOOMError();
 
 cleanup:
diff --git a/src/util/virkeyfile.c b/src/util/virkeyfile.c
index d77e95d..8bd930d 100644
--- a/src/util/virkeyfile.c
+++ b/src/util/virkeyfile.c
@@ -32,6 +32,7 @@
 #include "virhash.h"
 #include "virkeyfile.h"
 #include "virerror.h"
+#include "virstring.h"
 
 #define VIR_FROM_THIS VIR_FROM_CONF
 
@@ -121,7 +122,7 @@ static int virKeyFileParseGroup(virKeyFileParserCtxtPtr ctxt)
         return -1;
     }
 
-    if (!(ctxt->groupname = strndup(name, ctxt->cur - name))) {
+    if (VIR_STRNDUP(ctxt->groupname, name, ctxt->cur - name) < 0) {
         virReportOOMError();
         return -1;
     }
@@ -167,7 +168,7 @@ static int virKeyFileParseValue(virKeyFileParserCtxtPtr ctxt)
         return -1;
     }
 
-    if (!(key = strndup(keystart, ctxt->cur - keystart))) {
+    if (VIR_STRNDUP(key, keystart, ctxt->cur - keystart) < 0) {
         virReportOOMError();
         return -1;
     }
@@ -183,7 +184,7 @@ static int virKeyFileParseValue(virKeyFileParserCtxtPtr ctxt)
     len = ctxt->cur - valuestart;
     if (IS_EOF && !IS_EOL(CUR))
         len++;
-    if (!(value = strndup(valuestart, len))) {
+    if (VIR_STRNDUP(value, valuestart, len) < 0) {
         virReportOOMError();
         goto cleanup;
     }
diff --git a/src/util/virlockspace.c b/src/util/virlockspace.c
index 620a460..38f5669 100644
--- a/src/util/virlockspace.c
+++ b/src/util/virlockspace.c
@@ -70,7 +70,7 @@ static char *virLockSpaceGetResourcePath(virLockSpacePtr lockspace,
             return NULL;
         }
     } else {
-        if (!(ret = strdup(resname))) {
+        if (VIR_STRDUP(ret, resname) < 0) {
             virReportOOMError();
             return NULL;
         }
@@ -132,7 +132,7 @@ virLockSpaceResourceNew(virLockSpacePtr lockspace,
     res->fd = -1;
     res->flags = flags;
 
-    if (!(res->name = strdup(resname)))
+    if (VIR_STRDUP(res->name, resname) < 0)
         goto no_memory;
 
     if (!(res->path = virLockSpaceGetResourcePath(lockspace, resname)))
@@ -262,8 +262,7 @@ virLockSpacePtr virLockSpaceNew(const char *directory)
         return NULL;
     }
 
-    if (directory &&
-        !(lockspace->dir = strdup(directory)))
+    if (directory && VIR_STRDUP(lockspace->dir, directory) < 0)
         goto no_memory;
 
     if (!(lockspace->resources = virHashCreate(VIR_LOCKSPACE_TABLE_SIZE,
@@ -324,7 +323,7 @@ virLockSpacePtr virLockSpaceNewPostExecRestart(virJSONValuePtr object)
 
     if (virJSONValueObjectHasKey(object, "directory")) {
         const char *dir = virJSONValueObjectGetString(object, "directory");
-        if (!(lockspace->dir = strdup(dir))) {
+        if (VIR_STRDUP(lockspace->dir, dir) < 0) {
             virReportOOMError();
             goto error;
         }
@@ -362,7 +361,7 @@ virLockSpacePtr virLockSpaceNewPostExecRestart(virJSONValuePtr object)
             virLockSpaceResourceFree(res);
             goto error;
         }
-        if (!(res->name = strdup(tmp))) {
+        if (VIR_STRDUP(res->name, tmp) < 0) {
             virReportOOMError();
             virLockSpaceResourceFree(res);
             goto error;
@@ -374,7 +373,7 @@ virLockSpacePtr virLockSpaceNewPostExecRestart(virJSONValuePtr object)
             virLockSpaceResourceFree(res);
             goto error;
         }
-        if (!(res->path = strdup(tmp))) {
+        if (VIR_STRDUP(res->path, tmp) < 0) {
             virReportOOMError();
             virLockSpaceResourceFree(res);
             goto error;
diff --git a/src/util/virlog.c b/src/util/virlog.c
index bd47b38..921ffc5 100644
--- a/src/util/virlog.c
+++ b/src/util/virlog.c
@@ -557,8 +557,7 @@ virLogDefineFilter(const char *match,
         }
     }
 
-    mdup = strdup(match);
-    if (mdup == NULL) {
+    if (VIR_STRDUP(mdup, match) < 0) {
         i = -1;
         goto cleanup;
     }
@@ -667,8 +666,7 @@ virLogDefineOutput(virLogOutputFunc f,
     if (dest == VIR_LOG_TO_SYSLOG || dest == VIR_LOG_TO_FILE) {
         if (name == NULL)
             return -1;
-        ndup = strdup(name);
-        if (ndup == NULL)
+        if (VIR_STRDUP(ndup, name) < 0)
             return -1;
     }
 
@@ -1047,8 +1045,7 @@ virLogAddOutputToSyslog(virLogPriority priority,
      * ident needs to be kept around on Solaris
      */
     VIR_FREE(current_ident);
-    current_ident = strdup(ident);
-    if (current_ident == NULL)
+    if (VIR_STRDUP(current_ident, ident) < 0)
         return -1;
 
     openlog(current_ident, 0, 0);
@@ -1329,8 +1326,7 @@ virLogParseOutputs(const char *outputs)
             if (str == cur)
                 goto cleanup;
 #if HAVE_SYSLOG_H
-            name = strndup(str, cur - str);
-            if (name == NULL)
+            if (VIR_STRNDUP(name, str, cur - str) < 0)
                 goto cleanup;
             if (virLogAddOutputToSyslog(prio, name) == 0)
                 count++;
@@ -1346,8 +1342,7 @@ virLogParseOutputs(const char *outputs)
                 cur++;
             if (str == cur)
                 goto cleanup;
-            name = strndup(str, cur - str);
-            if (name == NULL)
+            if (VIR_STRNDUP(name, str, cur - str) < 0)
                 goto cleanup;
             if (virFileAbsPath(name, &abspath) < 0) {
                 VIR_FREE(name);
@@ -1424,8 +1419,7 @@ virLogParseFilters(const char *filters)
             cur++;
         if (str == cur)
             goto cleanup;
-        name = strndup(str, cur - str);
-        if (name == NULL)
+        if (VIR_STRNDUP(name, str, cur - str) < 0)
             goto cleanup;
         if (virLogDefineFilter(name, prio, flags) >= 0)
             count++;
diff --git a/src/util/virnetdevmacvlan.c b/src/util/virnetdevmacvlan.c
index 0c4fcbd..7892937 100644
--- a/src/util/virnetdevmacvlan.c
+++ b/src/util/virnetdevmacvlan.c
@@ -31,6 +31,7 @@
 #include "virmacaddr.h"
 #include "virerror.h"
 #include "virthread.h"
+#include "virstring.h"
 
 #define VIR_FROM_THIS VIR_FROM_NET
 
@@ -764,13 +765,13 @@ virNetDevMacVLanVPortProfileRegisterCallback(const char *ifname,
     if (virtPortProfile && virNetlinkEventServiceIsRunning(NETLINK_ROUTE)) {
         if (VIR_ALLOC(calld) < 0)
             goto memory_error;
-        if ((calld->cr_ifname = strdup(ifname)) == NULL)
+        if (VIR_STRDUP(calld->cr_ifname, ifname) < 0)
             goto memory_error;
         if (VIR_ALLOC(calld->virtPortProfile) < 0)
             goto memory_error;
         memcpy(calld->virtPortProfile, virtPortProfile, sizeof(*virtPortProfile));
         virMacAddrSet(&calld->macaddress, macaddress);
-        if ((calld->linkdev = strdup(linkdev)) == NULL)
+        if (VIR_STRDUP(calld->linkdev, linkdev) < 0)
             goto  memory_error;
         memcpy(calld->vmuuid, vmuuid, sizeof(calld->vmuuid));
 
@@ -927,13 +928,13 @@ create_name:
             VIR_FORCE_CLOSE(rc); /* sets rc to -1 */
             goto disassociate_exit;
         }
-        if (!(*res_ifname = strdup(cr_ifname))) {
+        if (VIR_STRDUP(*res_ifname, cr_ifname) < 0) {
             VIR_FORCE_CLOSE(rc); /* sets rc to -1 */
             virReportOOMError();
             goto disassociate_exit;
         }
     } else {
-        if (!(*res_ifname = strdup(cr_ifname))) {
+        if (VIR_STRDUP(*res_ifname, cr_ifname) < 0) {
             virReportOOMError();
             goto disassociate_exit;
         }
diff --git a/src/util/virnetdevtap.c b/src/util/virnetdevtap.c
index 0cd2e31..bcf5c39 100644
--- a/src/util/virnetdevtap.c
+++ b/src/util/virnetdevtap.c
@@ -64,8 +64,7 @@ virNetDevTapGetName(int tapfd, char **ifname)
         return -1;
     }
 
-    *ifname = strdup(ifr.ifr_name);
-    if (*ifname == NULL) {
+    if (VIR_STRDUP(*ifname, ifr.ifr_name) < 0) {
         virReportOOMError();
         return -1;
     }
@@ -204,7 +203,7 @@ int virNetDevTapCreate(char **ifname,
     }
 
     VIR_FREE(*ifname);
-    if (!(*ifname = strdup(ifr.ifr_name))) {
+    if (VIR_STRDUP(*ifname, ifr.ifr_name) < 0) {
         virReportOOMError();
         goto cleanup;
     }
diff --git a/src/util/virnetdevvportprofile.c b/src/util/virnetdevvportprofile.c
index 883aa46..ba48429 100644
--- a/src/util/virnetdevvportprofile.c
+++ b/src/util/virnetdevvportprofile.c
@@ -1034,8 +1034,7 @@ virNetDevVPortProfileOp8021Qbh(const char *ifname,
             goto cleanup;
         }
     } else {
-        physfndev = strdup(ifname);
-        if (!physfndev) {
+        if (VIR_STRDUP(physfndev, ifname) < 0) {
             virReportOOMError();
             rc = -1;
             goto cleanup;
diff --git a/src/util/virobject.c b/src/util/virobject.c
index 93e37e4..da5537b 100644
--- a/src/util/virobject.c
+++ b/src/util/virobject.c
@@ -28,6 +28,7 @@
 #include "viratomic.h"
 #include "virerror.h"
 #include "virlog.h"
+#include "virstring.h"
 
 #define VIR_FROM_THIS VIR_FROM_NONE
 
@@ -37,7 +38,7 @@ struct _virClass {
     virClassPtr parent;
 
     unsigned int magic;
-    const char *name;
+    char *name;
     size_t objectSize;
 
     virObjectDisposeCallback dispose;
@@ -135,7 +136,7 @@ virClassPtr virClassNew(virClassPtr parent,
         goto no_memory;
 
     klass->parent = parent;
-    if (!(klass->name = strdup(name)))
+    if (VIR_STRDUP(klass->name, name) < 0)
         goto no_memory;
     klass->magic = virAtomicIntInc(&magicCounter);
     klass->objectSize = objectSize;
diff --git a/src/util/virpci.c b/src/util/virpci.c
index 6ed6a90..2160403 100644
--- a/src/util/virpci.c
+++ b/src/util/virpci.c
@@ -1364,7 +1364,7 @@ virPCIGetAddrString(unsigned int domain,
 
     dev = virPCIDeviceNew(domain, bus, slot, function);
     if (dev != NULL) {
-        if ((*pciConfigAddr = strdup(dev->name)) == NULL) {
+        if (VIR_STRDUP(*pciConfigAddr, dev->name) < 0) {
             virReportOOMError();
             goto cleanup;
         }
@@ -2240,8 +2240,7 @@ virPCIGetNetName(char *device_link_sysfs_path, char **netname)
             continue;
 
         /* Assume a single directory entry */
-        *netname = strdup(entry->d_name);
-        if (!*netname)
+        if (VIR_STRDUP(*netname, entry->d_name) < 0)
             virReportOOMError();
         else
             ret = 0;
diff --git a/src/util/virsexpr.c b/src/util/virsexpr.c
index 23b6781..d621d8e 100644
--- a/src/util/virsexpr.c
+++ b/src/util/virsexpr.c
@@ -118,17 +118,11 @@ sexpr_string(const char *str, ssize_t len)
 
     if (ret == NULL)
         return ret;
-    ret->kind = SEXPR_VALUE;
-    if (len > 0) {
-        ret->u.value = strndup(str, len);
-    } else {
-        ret->u.value = strdup(str);
-    }
 
-    if (ret->u.value == NULL) {
+    ret->kind = SEXPR_VALUE;
+    if ((len > 0 && VIR_STRNDUP(ret->u.value, str, len) < 0) ||
+        (len <= 0 && VIR_STRDUP(ret->u.value, str) < 0))
         VIR_FREE(ret);
-        return NULL;
-    }
 
     return ret;
 }
@@ -325,8 +319,7 @@ _string2sexpr(const char *buffer, size_t * end)
                 ptr++;
             }
 
-            ret->u.value = strndup(start, ptr - start);
-            if (ret->u.value == NULL) {
+            if (VIR_STRNDUP(ret->u.value, start, ptr - start) < 0) {
                 virReportOOMError();
                 goto error;
             }
@@ -341,8 +334,7 @@ _string2sexpr(const char *buffer, size_t * end)
                 ptr++;
             }
 
-            ret->u.value = strndup(start, ptr - start);
-            if (ret->u.value == NULL) {
+            if (VIR_STRNDUP(ret->u.value, start, ptr - start) < 0) {
                 virReportOOMError();
                 goto error;
             }
@@ -403,9 +395,7 @@ sexpr_lookup_key(const struct sexpr *sexpr, const char *node)
     if ((node == NULL) || (sexpr == NULL))
         return NULL;
 
-    buffer = strdup(node);
-
-    if (buffer == NULL) {
+    if (VIR_STRDUP(buffer, node) < 0) {
         virReportOOMError();
         return NULL;
     }
@@ -528,8 +518,7 @@ int sexpr_node_copy(const struct sexpr *sexpr, const char *node, char **dst)
     const char *val = sexpr_node(sexpr, node);
 
     if (val && *val) {
-        *dst = strdup(val);
-        if (!(*dst))
+        if (VIR_STRDUP(*dst, val) < 0)
             return -1;
     } else {
         *dst = NULL;
diff --git a/src/util/virsocketaddr.c b/src/util/virsocketaddr.c
index d6a0d93..4fac526 100644
--- a/src/util/virsocketaddr.c
+++ b/src/util/virsocketaddr.c
@@ -272,7 +272,7 @@ virSocketAddrFormatFull(virSocketAddrPtr addr,
                             separator ? separator : ":") < 0)
                 goto no_memory;
         } else {
-            if (!(addrstr = strdup("127.0.0.1")))
+            if (VIR_STRDUP(addrstr, "127.0.0.1") < 0)
                 goto no_memory;
         }
         return addrstr;
@@ -293,7 +293,7 @@ virSocketAddrFormatFull(virSocketAddrPtr addr,
         if (virAsprintf(&addrstr, "%s%s%s", host, separator, port) == -1)
             goto no_memory;
     } else {
-        if (!(addrstr = strdup(host)))
+        if (VIR_STRDUP(addrstr, host) < 0)
             goto no_memory;
     }
 
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index c7bb85a..04306c1 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -228,8 +228,7 @@ cowGetBackingStore(char **res,
         return BACKING_STORE_OK;
     }
 
-    *res = strndup((const char*)buf + 4+4, COW_FILENAME_MAXLEN);
-    if (*res == NULL) {
+    if (VIR_STRNDUP(*res, (const char*)buf + 4+4, COW_FILENAME_MAXLEN) < 0) {
         virReportOOMError();
         return BACKING_STORE_ERROR;
     }
@@ -440,8 +439,7 @@ vmdk4GetBackingStore(char **res,
         goto cleanup;
     }
     *end = '\0';
-    *res = strdup(start);
-    if (*res == NULL) {
+    if (VIR_STRDUP(*res, start) < 0) {
         virReportOOMError();
         goto cleanup;
     }
@@ -775,8 +773,7 @@ virStorageFileGetMetadataInternal(const char *path,
 
         meta->backingStoreIsFile = false;
         if (backing != NULL) {
-            meta->backingStore = strdup(backing);
-            if (meta->backingStore == NULL) {
+            if (VIR_STRDUP(meta->backingStore, backing) < 0) {
                 virReportOOMError();
                 VIR_FREE(backing);
                 goto cleanup;
@@ -1096,7 +1093,7 @@ int virStorageFileIsSharedFSType(const char *path,
     struct statfs sb;
     int statfs_ret;
 
-    if ((dirpath = strdup(path)) == NULL) {
+    if (VIR_STRDUP(dirpath, path) < 0) {
         virReportOOMError();
         return -1;
     }
diff --git a/src/util/virstring.c b/src/util/virstring.c
index 4a55873..2f672bc 100644
--- a/src/util/virstring.c
+++ b/src/util/virstring.c
@@ -85,7 +85,7 @@ char **virStringSplit(const char *string,
             if (VIR_RESIZE_N(tokens, maxtokens, ntokens, 1) < 0)
                 goto no_memory;
 
-            if (!(tokens[ntokens] = strndup(remainder, len)))
+            if (VIR_STRNDUP(tokens[ntokens], remainder, len) < 0)
                 goto no_memory;
             ntokens++;
             remainder = tmp + delimlen;
@@ -96,7 +96,7 @@ char **virStringSplit(const char *string,
         if (VIR_RESIZE_N(tokens, maxtokens, ntokens, 1) < 0)
             goto no_memory;
 
-        if (!(tokens[ntokens] = strdup(remainder)))
+        if (VIR_STRDUP(tokens[ntokens], remainder) < 0)
             goto no_memory;
         ntokens++;
     }
@@ -145,7 +145,7 @@ char *virStringJoin(const char **strings,
     }
     ret = virBufferContentAndReset(&buf);
     if (!ret) {
-        if (!(ret = strdup(""))) {
+        if (VIR_STRDUP(ret, "") < 0) {
             virReportOOMError();
             return NULL;
         }
diff --git a/src/util/virsysinfo.c b/src/util/virsysinfo.c
index 2efe634..2c6bbcf 100644
--- a/src/util/virsysinfo.c
+++ b/src/util/virsysinfo.c
@@ -144,16 +144,14 @@ virSysinfoParseSystem(const char *base, virSysinfoDefPtr ret)
     cur = strchr(cur, ':') + 1;
     eol = strchr(cur, '\n');
     virSkipSpaces(&cur);
-    if (eol &&
-       ((ret->system_family = strndup(cur, eol - cur)) == NULL))
+    if (eol && VIR_STRNDUP(ret->system_family, cur, eol - cur) < 0)
          goto no_memory;
 
     if ((cur = strstr(base, "model")) != NULL) {
         cur = strchr(cur, ':') + 1;
         eol = strchr(cur, '\n');
         virSkipSpaces(&cur);
-        if (eol && ((ret->system_serial = strndup(cur, eol - cur))
-                                                           == NULL))
+        if (eol && VIR_STRNDUP(ret->system_serial, cur, eol - cur) < 0)
             goto no_memory;
     }
 
@@ -161,8 +159,7 @@ virSysinfoParseSystem(const char *base, virSysinfoDefPtr ret)
         cur = strchr(cur, ':') + 1;
         eol = strchr(cur, '\n');
         virSkipSpaces(&cur);
-        if (eol && ((ret->system_version = strndup(cur, eol - cur))
-                                                            == NULL))
+        if (eol && VIR_STRNDUP(ret->system_version, cur, eol - cur) < 0)
             goto no_memory;
     }
 
@@ -190,18 +187,14 @@ virSysinfoParseProcessor(const char *base, virSysinfoDefPtr ret)
         processor = &ret->processor[ret->nprocessor - 1];
 
         virSkipSpaces(&cur);
-        if (eol &&
-            ((processor->processor_socket_destination = strndup
-                                     (cur, eol - cur)) == NULL))
+        if (eol && VIR_STRNDUP(processor->processor_socket_destination, cur, eol - cur) < 0)
             goto no_memory;
 
         if ((cur = strstr(base, "cpu")) != NULL) {
             cur = strchr(cur, ':') + 1;
             eol = strchr(cur, '\n');
             virSkipSpaces(&cur);
-            if (eol &&
-               ((processor->processor_type = strndup(cur, eol - cur))
-                                                             == NULL))
+            if (eol && VIR_STRNDUP(processor->processor_type, cur, eol - cur) < 0)
                 goto no_memory;
         }
 
@@ -209,9 +202,7 @@ virSysinfoParseProcessor(const char *base, virSysinfoDefPtr ret)
             cur = strchr(cur, ':') + 1;
             eol = strchr(cur, '\n');
             virSkipSpaces(&cur);
-            if (eol &&
-               ((processor->processor_version = strndup(cur, eol - cur))
-                                                                == NULL))
+            if (eol && VIR_STRNDUP(processor->processor_version, cur, eol - cur) < 0)
                 goto no_memory;
         }
 
@@ -271,15 +262,14 @@ virSysinfoParseSystem(const char *base, virSysinfoDefPtr ret)
     eol = strchr(cur, '\n');
     virSkipSpaces(&cur);
     if (eol &&
-       ((ret->system_family = strndup(cur, eol - cur)) == NULL))
+       VIR_STRNDUP(ret->system_family, cur, eol - cur) < 0)
          goto no_memory;
 
     if ((cur = strstr(base, "model")) != NULL) {
         cur = strchr(cur, ':') + 1;
         eol = strchr(cur, '\n');
         virSkipSpaces(&cur);
-        if (eol && ((ret->system_serial = strndup(cur, eol - cur))
-                                                           == NULL))
+        if (eol && VIR_STRNDUP(ret->system_serial, cur, eol - cur) < 0)
             goto no_memory;
     }
 
@@ -287,8 +277,7 @@ virSysinfoParseSystem(const char *base, virSysinfoDefPtr ret)
         cur = strchr(cur, ':') + 1;
         eol = strchr(cur, '\n');
         virSkipSpaces(&cur);
-        if (eol && ((ret->system_version = strndup(cur, eol - cur))
-                                                            == NULL))
+        if (eol && VIR_STRNDUP(ret->system_version, cur, eol - cur) < 0)
             goto no_memory;
     }
 
@@ -313,9 +302,7 @@ virSysinfoParseProcessor(const char *base, virSysinfoDefPtr ret)
     eol = strchr(base, '\n');
     cur = strchr(base, ':') + 1;
     virSkipSpaces(&cur);
-    if (eol &&
-        ((processor_type = strndup(cur, eol - cur))
-         == NULL))
+    if (eol && VIR_STRNDUP(processor_type, cur, eol - cur) < 0)
         goto no_memory;
     base = cur;
 
@@ -331,12 +318,11 @@ virSysinfoParseProcessor(const char *base, virSysinfoDefPtr ret)
 
         virSkipSpaces(&cur);
         if (eol &&
-            ((processor->processor_socket_destination = strndup
-                                     (cur, eol - cur)) == NULL))
+            VIR_STRNDUP(processor->processor_socket_destination, (cur, eol - cur) < 0)
             goto no_memory;
 
         if (processor_type &&
-            !(processor->processor_type = strdup(processor_type)))
+            VIR_STRNDUP(processor->processor_type, processor_type) < 0)
             goto no_memory;
 
         base = cur;
@@ -408,7 +394,7 @@ virSysinfoParseDelimited(const char *base, const char *name, char **value,
         start += 1;
         end = strchrnul(start, delim2);
         virSkipSpaces(&start);
-        if (!((*value) = strndup(start, end - start))) {
+        if (VIR_STRNDUP((*value), start, end - start) < 0) {
             virReportOOMError();
             goto error;
         }
@@ -462,7 +448,10 @@ virSysinfoParseProcessor(const char *base, virSysinfoDefPtr ret)
             goto cleanup;
         }
         processor = &ret->processor[ret->nprocessor - 1];
-        processor->processor_manufacturer = strdup(manufacturer);
+        if (VIR_STRDUP(processor->processor_manufacturer, manufacturer) < 0) {
+            virReportOOMError();
+            goto cleanup;
+        }
         if (!virSysinfoParseDelimited(procline, "version",
                                       &processor->processor_version,
                                       '=', ',') ||
@@ -556,25 +545,25 @@ virSysinfoParseBIOS(const char *base, virSysinfoDefPtr ret)
     if ((cur = strstr(base, "Vendor: ")) != NULL) {
         cur += 8;
         eol = strchr(cur, '\n');
-        if ((eol) && ((ret->bios_vendor = strndup(cur, eol - cur)) == NULL))
+        if (eol && VIR_STRNDUP(ret->bios_vendor, cur, eol - cur) < 0)
             goto no_memory;
     }
     if ((cur = strstr(base, "Version: ")) != NULL) {
         cur += 9;
         eol = strchr(cur, '\n');
-        if ((eol) && ((ret->bios_version = strndup(cur, eol - cur)) == NULL))
+        if (eol && VIR_STRNDUP(ret->bios_version, cur, eol - cur) < 0)
             goto no_memory;
     }
     if ((cur = strstr(base, "Release Date: ")) != NULL) {
         cur += 14;
         eol = strchr(cur, '\n');
-        if ((eol) && ((ret->bios_date = strndup(cur, eol - cur)) == NULL))
+        if (eol && VIR_STRNDUP(ret->bios_date, cur, eol - cur) < 0)
             goto no_memory;
     }
     if ((cur = strstr(base, "BIOS Revision: ")) != NULL) {
         cur += 15;
         eol = strchr(cur, '\n');
-        if ((eol) && ((ret->bios_release = strndup(cur, eol - cur)) == NULL))
+        if (eol && VIR_STRNDUP(ret->bios_release, cur, eol - cur) < 0)
             goto no_memory;
     }
 
@@ -596,44 +585,43 @@ virSysinfoParseSystem(const char *base, virSysinfoDefPtr ret)
     if ((cur = strstr(base, "Manufacturer: ")) != NULL) {
         cur += 14;
         eol = strchr(cur, '\n');
-        if ((eol) &&
-            ((ret->system_manufacturer = strndup(cur, eol - cur)) == NULL))
+        if (eol && VIR_STRNDUP(ret->system_manufacturer, cur, eol - cur) < 0)
             goto no_memory;
     }
     if ((cur = strstr(base, "Product Name: ")) != NULL) {
         cur += 14;
         eol = strchr(cur, '\n');
-        if ((eol) && ((ret->system_product = strndup(cur, eol - cur)) == NULL))
+        if (eol && VIR_STRNDUP(ret->system_product, cur, eol - cur) < 0)
             goto no_memory;
     }
     if ((cur = strstr(base, "Version: ")) != NULL) {
         cur += 9;
         eol = strchr(cur, '\n');
-        if ((eol) && ((ret->system_version = strndup(cur, eol - cur)) == NULL))
+        if (eol && VIR_STRNDUP(ret->system_version, cur, eol - cur) < 0)
             goto no_memory;
     }
     if ((cur = strstr(base, "Serial Number: ")) != NULL) {
         cur += 15;
         eol = strchr(cur, '\n');
-        if ((eol) && ((ret->system_serial = strndup(cur, eol - cur)) == NULL))
+        if (eol && VIR_STRNDUP(ret->system_serial, cur, eol - cur) < 0)
             goto no_memory;
     }
     if ((cur = strstr(base, "UUID: ")) != NULL) {
         cur += 6;
         eol = strchr(cur, '\n');
-        if ((eol) && ((ret->system_uuid = strndup(cur, eol - cur)) == NULL))
+        if (eol && VIR_STRNDUP(ret->system_uuid, cur, eol - cur) < 0)
             goto no_memory;
     }
     if ((cur = strstr(base, "SKU Number: ")) != NULL) {
         cur += 12;
         eol = strchr(cur, '\n');
-        if ((eol) && ((ret->system_sku = strndup(cur, eol - cur)) == NULL))
+        if (eol && VIR_STRNDUP(ret->system_sku, cur, eol - cur) < 0)
             goto no_memory;
     }
     if ((cur = strstr(base, "Family: ")) != NULL) {
         cur += 8;
         eol = strchr(cur, '\n');
-        if ((eol) && ((ret->system_family = strndup(cur, eol - cur)) == NULL))
+        if (eol && VIR_STRNDUP(ret->system_family, cur, eol - cur) < 0)
             goto no_memory;
     }
 
@@ -663,98 +651,88 @@ virSysinfoParseProcessor(const char *base, virSysinfoDefPtr ret)
             cur += 20;
             eol = strchr(cur, '\n');
             virSkipSpacesBackwards(cur, &eol);
-            if ((eol) &&
-                ((processor->processor_socket_destination
-                  = strndup(cur, eol - cur)) == NULL))
+            if (eol &&
+                VIR_STRNDUP(processor->processor_socket_destination, cur, eol - cur) < 0)
                 goto no_memory;
         }
         if ((cur = strstr(base, "Type: ")) != NULL) {
             cur += 6;
             eol = strchr(cur, '\n');
             virSkipSpacesBackwards(cur, &eol);
-            if ((eol) &&
-                ((processor->processor_type = strndup(cur, eol - cur)) == NULL))
+            if (eol &&
+                VIR_STRNDUP(processor->processor_type, cur, eol - cur) < 0)
                 goto no_memory;
         }
         if ((cur = strstr(base, "Family: ")) != NULL) {
             cur += 8;
             eol = strchr(cur, '\n');
             virSkipSpacesBackwards(cur, &eol);
-            if ((eol) &&
-                ((processor->processor_family = strndup(cur,
-                                                        eol - cur)) == NULL))
+            if (eol &&
+                VIR_STRNDUP(processor->processor_family, cur, eol - cur) < 0)
                 goto no_memory;
         }
         if ((cur = strstr(base, "Manufacturer: ")) != NULL) {
             cur += 14;
             eol = strchr(cur, '\n');
             virSkipSpacesBackwards(cur, &eol);
-            if ((eol) &&
-                ((processor->processor_manufacturer
-                  = strndup(cur, eol - cur)) == NULL))
+            if (eol &&
+                VIR_STRNDUP(processor->processor_manufacturer, cur, eol - cur) < 0)
                 goto no_memory;
         }
         if ((cur = strstr(base, "Signature: ")) != NULL) {
             cur += 11;
             eol = strchr(cur, '\n');
             virSkipSpacesBackwards(cur, &eol);
-            if ((eol) &&
-                ((processor->processor_signature
-                  = strndup(cur, eol - cur)) == NULL))
+            if (eol &&
+                VIR_STRNDUP(processor->processor_signature, cur, eol - cur) < 0)
                 goto no_memory;
         }
         if ((cur = strstr(base, "Version: ")) != NULL) {
             cur += 9;
             eol = strchr(cur, '\n');
             virSkipSpacesBackwards(cur, &eol);
-            if ((eol) &&
-                ((processor->processor_version = strndup(cur,
-                                                         eol - cur)) == NULL))
+            if (eol &&
+                VIR_STRNDUP(processor->processor_version, cur, eol - cur) < 0)
                 goto no_memory;
         }
         if ((cur = strstr(base, "External Clock: ")) != NULL) {
             cur += 16;
             eol = strchr(cur, '\n');
             virSkipSpacesBackwards(cur, &eol);
-            if ((eol) &&
-                ((processor->processor_external_clock
-                  = strndup(cur, eol - cur)) == NULL))
+            if (eol &&
+                VIR_STRNDUP(processor->processor_external_clock, cur, eol - cur) < 0)
                 goto no_memory;
         }
         if ((cur = strstr(base, "Max Speed: ")) != NULL) {
             cur += 11;
             eol = strchr(cur, '\n');
             virSkipSpacesBackwards(cur, &eol);
-            if ((eol) &&
-                ((processor->processor_max_speed
-                  = strndup(cur, eol - cur)) == NULL))
+            if (eol &&
+                VIR_STRNDUP(processor->processor_max_speed, cur, eol - cur) < 0)
                 goto no_memory;
         }
         if ((cur = strstr(base, "Status: ")) != NULL) {
             cur += 8;
             eol = strchr(cur, '\n');
             virSkipSpacesBackwards(cur, &eol);
-            if ((eol) &&
-                ((processor->processor_status = strndup(cur,
-                                                        eol - cur)) == NULL))
+            if (eol &&
+                VIR_STRNDUP(processor->processor_status, cur, eol - cur) < 0)
                 goto no_memory;
         }
         if ((cur = strstr(base, "Serial Number: ")) != NULL) {
             cur += 15;
             eol = strchr(cur, '\n');
             virSkipSpacesBackwards(cur, &eol);
-            if ((eol) &&
-                ((processor->processor_serial_number
-                  = strndup(cur, eol - cur)) == NULL))
+            if (eol &&
+                VIR_STRNDUP(processor->processor_serial_number, cur, eol - cur) < 0)
                 goto no_memory;
         }
         if ((cur = strstr(base, "Part Number: ")) != NULL) {
             cur += 13;
             eol = strchr(cur, '\n');
             virSkipSpacesBackwards(cur, &eol);
-            if ((eol) &&
-                ((processor->processor_part_number
-                  = strndup(cur, eol - cur)) == NULL))
+            if (eol &&
+                VIR_STRNDUP(processor->processor_part_number, cur, eol - cur) < 0)
                 goto no_memory;
         }
 
@@ -790,86 +768,80 @@ virSysinfoParseMemory(const char *base, virSysinfoDefPtr ret)
                 goto next;
 
             virSkipSpacesBackwards(cur, &eol);
-            if ((eol) &&
-                ((memory->memory_size = strndup(cur, eol - cur)) == NULL))
+            if (eol &&
+                VIR_STRNDUP(memory->memory_size, cur, eol - cur) < 0)
                 goto no_memory;
         }
         if ((cur = strstr(base, "Form Factor: ")) != NULL) {
             cur += 13;
             eol = strchr(cur, '\n');
             virSkipSpacesBackwards(cur, &eol);
-            if ((eol) &&
-                ((memory->memory_form_factor = strndup(cur,
-                                                       eol - cur)) == NULL))
+            if (eol &&
+                VIR_STRNDUP(memory->memory_form_factor, cur, eol - cur) < 0)
                 goto no_memory;
         }
         if ((cur = strstr(base, "Locator: ")) != NULL) {
             cur += 9;
             eol = strchr(cur, '\n');
             virSkipSpacesBackwards(cur, &eol);
-            if ((eol) &&
-                ((memory->memory_locator = strndup(cur, eol - cur)) == NULL))
+            if (eol &&
+                VIR_STRNDUP(memory->memory_locator, cur, eol - cur) < 0)
                 goto no_memory;
         }
         if ((cur = strstr(base, "Bank Locator: ")) != NULL) {
             cur += 14;
             eol = strchr(cur, '\n');
             virSkipSpacesBackwards(cur, &eol);
-            if ((eol) &&
-                ((memory->memory_bank_locator = strndup(cur,
-                                                        eol - cur)) == NULL))
+            if (eol &&
+                VIR_STRNDUP(memory->memory_bank_locator, cur, eol - cur) < 0)
                 goto no_memory;
         }
         if ((cur = strstr(base, "Type: ")) != NULL) {
             cur += 6;
             eol = strchr(cur, '\n');
             virSkipSpacesBackwards(cur, &eol);
-            if ((eol) &&
-                ((memory->memory_type = strndup(cur, eol - cur)) == NULL))
+            if (eol &&
+                VIR_STRNDUP(memory->memory_type, cur, eol - cur) < 0)
                 goto no_memory;
         }
         if ((cur = strstr(base, "Type Detail: ")) != NULL) {
             cur += 13;
             eol = strchr(cur, '\n');
             virSkipSpacesBackwards(cur, &eol);
-            if ((eol) &&
-                ((memory->memory_type_detail = strndup(cur,
-                                                       eol - cur)) == NULL))
+            if (eol &&
+                VIR_STRNDUP(memory->memory_type_detail, cur, eol - cur) < 0)
                 goto no_memory;
         }
         if ((cur = strstr(base, "Speed: ")) != NULL) {
             cur += 7;
             eol = strchr(cur, '\n');
             virSkipSpacesBackwards(cur, &eol);
-            if ((eol) &&
-                ((memory->memory_speed = strndup(cur, eol - cur)) == NULL))
+            if (eol &&
+                VIR_STRNDUP(memory->memory_speed, cur, eol - cur) < 0)
                 goto no_memory;
         }
         if ((cur = strstr(base, "Manufacturer: ")) != NULL) {
             cur += 14;
             eol = strchr(cur, '\n');
             virSkipSpacesBackwards(cur, &eol);
-            if ((eol) &&
-                ((memory->memory_manufacturer = strndup(cur,
-                                                        eol - cur)) == NULL))
+            if (eol &&
+                VIR_STRNDUP(memory->memory_manufacturer, cur, eol - cur) < 0)
                 goto no_memory;
         }
         if ((cur = strstr(base, "Serial Number: ")) != NULL) {
             cur += 15;
             eol = strchr(cur, '\n');
             virSkipSpacesBackwards(cur, &eol);
-            if ((eol) &&
-                ((memory->memory_serial_number = strndup(cur,
-                                                         eol - cur)) == NULL))
+            if (eol &&
+                VIR_STRNDUP(memory->memory_serial_number, cur, eol - cur) < 0)
                 goto no_memory;
         }
         if ((cur = strstr(base, "Part Number: ")) != NULL) {
             cur += 13;
             eol = strchr(cur, '\n');
             virSkipSpacesBackwards(cur, &eol);
-            if ((eol) &&
-                ((memory->memory_part_number = strndup(cur,
-                                                       eol - cur)) == NULL))
+            if (eol &&
+                VIR_STRNDUP(memory->memory_part_number, cur, eol - cur) < 0)
                 goto no_memory;
         }
 
diff --git a/src/util/virtypedparam.c b/src/util/virtypedparam.c
index a9f8a33..cc352ff 100644
--- a/src/util/virtypedparam.c
+++ b/src/util/virtypedparam.c
@@ -150,9 +150,7 @@ virTypedParameterAssign(virTypedParameterPtr param, const char *name,
         break;
     case VIR_TYPED_PARAM_STRING:
         param->value.s = va_arg(ap, char *);
-        if (!param->value.s)
-            param->value.s = strdup("");
-        if (!param->value.s) {
+        if (!param->value.s && VIR_STRDUP(param->value.s, "") < 0) {
             virReportOOMError();
             goto cleanup;
         }
@@ -248,7 +246,7 @@ virTypedParameterAssignFromStr(virTypedParameterPtr param, const char *name,
         }
         break;
     case VIR_TYPED_PARAM_STRING:
-        if (!(param->value.s = strdup(val))) {
+        if (VIR_STRDUP(param->value.s, val) < 0) {
             virReportOOMError();
             goto cleanup;
         }
@@ -913,7 +911,7 @@ virTypedParamsAddString(virTypedParameterPtr *params,
     }
     *maxparams = max;
 
-    if (value && !(str = strdup(value))) {
+    if (value && VIR_STRDUP(str, value) < 0) {
         virReportOOMError();
         goto error;
     }
diff --git a/src/util/viruri.c b/src/util/viruri.c
index 2a75425..ba46851 100644
--- a/src/util/viruri.c
+++ b/src/util/viruri.c
@@ -37,9 +37,9 @@ virURIParamAppend(virURIPtr uri,
     char *pname = NULL;
     char *pvalue = NULL;
 
-    if (!(pname = strdup(name)))
+    if (VIR_STRDUP(pname, name) < 0)
         goto no_memory;
-    if (!(pvalue = strdup(value)))
+    if (VIR_STRDUP(pvalue, value) < 0)
         goto no_memory;
 
     if (VIR_RESIZE_N(uri->params, uri->paramsAlloc, uri->paramsCount, 1) < 0)
@@ -171,29 +171,29 @@ virURIParse(const char *uri)
         goto no_memory;
 
     if (xmluri->scheme &&
-        !(ret->scheme = strdup(xmluri->scheme)))
+        VIR_STRDUP(ret->scheme, xmluri->scheme) < 0)
         goto no_memory;
     if (xmluri->server &&
-        !(ret->server = strdup(xmluri->server)))
+        VIR_STRDUP(ret->server, xmluri->server) < 0)
         goto no_memory;
     ret->port = xmluri->port;
     if (xmluri->path &&
-        !(ret->path = strdup(xmluri->path)))
+        VIR_STRDUP(ret->path, xmluri->path) < 0)
         goto no_memory;
 #ifdef HAVE_XMLURI_QUERY_RAW
     if (xmluri->query_raw &&
-        !(ret->query = strdup(xmluri->query_raw)))
+        VIR_STRDUP(ret->query, xmluri->query_raw) < 0)
         goto no_memory;
 #else
     if (xmluri->query &&
-        !(ret->query = strdup(xmluri->query)))
+        VIR_STRDUP(ret->query, xmluri->query) < 0)
         goto no_memory;
 #endif
     if (xmluri->fragment &&
-        !(ret->fragment = strdup(xmluri->fragment)))
+        VIR_STRDUP(ret->fragment, xmluri->fragment) < 0)
         goto no_memory;
     if (xmluri->user &&
-        !(ret->user = strdup(xmluri->user)))
+        VIR_STRDUP(ret->user, xmluri->user) < 0)
         goto no_memory;
 
     /* First check: does it even make sense to jump inside */
diff --git a/src/util/virutil.c b/src/util/virutil.c
index dc14c15..5b3c1f3 100644
--- a/src/util/virutil.c
+++ b/src/util/virutil.c
@@ -547,7 +547,7 @@ virFileResolveLinkHelper(const char *linkpath,
             return -1;
 
         if (!S_ISLNK(st.st_mode)) {
-            if (!(*resultpath = strdup(linkpath)))
+            if (VIR_STRDUP(*resultpath, linkpath) < 0)
                 return -1;
             return 0;
         }
@@ -622,9 +622,10 @@ char *virFindFileInPath(const char *file)
      * copy of that path, after validating that it is executable
      */
     if (IS_ABSOLUTE_FILE_NAME(file)) {
-        if (virFileIsExecutable(file))
-            return strdup(file);
-        else
+        if (virFileIsExecutable(file)) {
+            ignore_value(VIR_STRDUP(path, file));
+            return path;
+        } else
             return NULL;
     }
 
@@ -640,7 +641,7 @@ char *virFindFileInPath(const char *file)
     /* copy PATH env so we can tweak it */
     path = getenv("PATH");
 
-    if (path == NULL || (path = strdup(path)) == NULL)
+    if (path == NULL || VIR_STRDUP(path, path) < 0)
         return NULL;
 
     /* for each path segment, append the file to search for and test for
@@ -1295,7 +1296,7 @@ virFileMakePathWithMode(const char *path,
     int ret = -1;
     char *tmp;
 
-    if ((tmp = strdup(path)) == NULL)
+    if (VIR_STRDUP(tmp, path) < 0)
         goto cleanup;
 
     ret = virFileMakePathHelper(tmp, mode);
@@ -1502,7 +1503,7 @@ int virFileAbsPath(const char *path, char **abspath)
     char *buf;
 
     if (path[0] == '/') {
-        if (!(*abspath = strdup(path)))
+        if (VIR_STRDUP(*abspath, path) < 0)
             return -1;
     } else {
         buf = getcwd(NULL, 0);
@@ -1527,8 +1528,7 @@ virFileSanitizePath(const char *path)
     char *cleanpath;
     int idx = 0;
 
-    cleanpath = strdup(path);
-    if (!cleanpath) {
+    if (VIR_STRDUP(cleanpath, path) < 0) {
         virReportOOMError();
         return NULL;
     }
@@ -1962,7 +1962,7 @@ char *virGetHostname(virConnectPtr conn ATTRIBUTE_UNUSED)
          * string as-is; it's up to callers to check whether "localhost"
          * is allowed.
          */
-        result = strdup(hostname);
+        r = VIR_STRDUP(result, hostname);
         goto check_and_return;
     }
 
@@ -1977,7 +1977,7 @@ char *virGetHostname(virConnectPtr conn ATTRIBUTE_UNUSED)
     if (r != 0) {
         VIR_WARN("getaddrinfo failed for '%s': %s",
                  hostname, gai_strerror(r));
-        result = strdup(hostname);
+        r = VIR_STRDUP(result, hostname);
         goto check_and_return;
     }
 
@@ -1990,15 +1990,15 @@ char *virGetHostname(virConnectPtr conn ATTRIBUTE_UNUSED)
          * localhost.  Ignore the canonicalized name and just return the
          * original hostname
          */
-        result = strdup(hostname);
+        r = VIR_STRDUP(result, hostname);
     else
         /* Caller frees this string. */
-        result = strdup(info->ai_canonname);
+        r = VIR_STRDUP(result, info->ai_canonname);
 
     freeaddrinfo(info);
 
 check_and_return:
-    if (result == NULL)
+    if (r < 0)
         virReportOOMError();
     return result;
 }
@@ -2051,14 +2051,10 @@ static char *virGetUserEnt(uid_t uid,
         return NULL;
     }
 
-    if (field == VIR_USER_ENT_DIRECTORY)
-        ret = strdup(pw->pw_dir);
-    else
-        ret = strdup(pw->pw_name);
-
-    VIR_FREE(strbuf);
-    if (!ret)
+    if (VIR_STRDUP(ret, field == VIR_USER_ENT_DIRECTORY ?
+                   pw->pw_dir : pw->pw_name) < 0)
         virReportOOMError();
+    VIR_FREE(strbuf);
 
     return ret;
 }
@@ -2104,12 +2100,10 @@ static char *virGetGroupEnt(gid_t gid)
         return NULL;
     }
 
-    ret = strdup(gr->gr_name);
-
-    VIR_FREE(strbuf);
-    if (!ret)
+    if (VIR_STRDUP(ret, gr->gr_name) < 0)
         virReportOOMError();
 
+    VIR_FREE(strbuf);
     return ret;
 }
 
@@ -2444,7 +2438,7 @@ virGetWin32SpecialFolder(int csidl, char **path)
 
     if (SHGetSpecialFolderLocation(NULL, csidl, &pidl) == S_OK) {
         if (SHGetPathFromIDList(pidl, buf)) {
-            if (!(*path = strdup(buf))) {
+            if (VIR_STRDUP(*path, buf) < 0) {
                 virReportOOMError();
                 ret = -1;
             }
@@ -2478,7 +2472,7 @@ virGetWin32DirectoryRoot(char **path)
         strcpy(windowsdir, "C:\\");
     }
 
-    if (!(*path = strdup(windowsdir))) {
+    if (VIR_STRDUP(*path, windowsdir) < 0) {
         virReportOOMError();
         ret = -1;
     }
@@ -2517,7 +2511,7 @@ virGetUserDirectory(void)
         dir = getenv("USERPROFILE");
 
     if (dir) {
-        if (!(ret = strdup(dir))) {
+        if (VIR_STRDUP(ret, dir) < 0) {
             virReportOOMError();
             return NULL;
         }
@@ -2809,7 +2803,8 @@ char *virFileFindMountPoint(const char *type)
 
     while (getmntent_r(f, &mb, mntbuf, sizeof(mntbuf))) {
         if (STREQ(mb.mnt_type, type)) {
-            ret = strdup(mb.mnt_dir);
+            if (VIR_STRDUP(ret, mb.mnt_dir) < 0)
+                virReportOOMError();
             goto cleanup;
         }
     }
@@ -3120,7 +3115,7 @@ virReadFCHost(const char *sysfs_prefix,
     else
         p = buf;
 
-    if (!(*result = strndup(p, sizeof(buf)))) {
+    if (VIR_STRNDUP(*result, p, sizeof(buf)) < 0) {
         virReportOOMError();
         goto cleanup;
     }
@@ -3347,7 +3342,7 @@ virGetFCHostNameByWWN(const char *sysfs_prefix,
             continue;
         }
 
-        ret = strdup(entry->d_name);
+        ignore_value(VIR_STRDUP(ret, entry->d_name));
         break;
     }
 
@@ -3432,7 +3427,7 @@ virFindFCHostCapableVport(const char *sysfs_prefix)
         if ((strlen(max_vports) >= strlen(vports)) ||
             ((strlen(max_vports) == strlen(vports)) &&
              strcmp(max_vports, vports) > 0)) {
-            ret = strdup(entry->d_name);
+            ignore_value(VIR_STRDUP(ret, entry->d_name));
             goto cleanup;
         }
 
diff --git a/src/util/virxml.c b/src/util/virxml.c
index 26120b6..0d8584d 100644
--- a/src/util/virxml.c
+++ b/src/util/virxml.c
@@ -87,11 +87,9 @@ virXPathString(const char *xpath,
         xmlXPathFreeObject(obj);
         return NULL;
     }
-    ret = strdup((char *) obj->stringval);
-    xmlXPathFreeObject(obj);
-    if (ret == NULL) {
+    if (VIR_STRDUP(ret, (char *) obj->stringval) < 0)
         virReportOOMError();
-    }
+    xmlXPathFreeObject(obj);
     return ret;
 }
 
-- 
1.8.1.5


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