]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: use g_strdup instead of VIR_STRDUP
authorJán Tomko <jtomko@redhat.com>
Sun, 20 Oct 2019 11:49:46 +0000 (13:49 +0200)
committerJán Tomko <jtomko@redhat.com>
Mon, 21 Oct 2019 10:51:59 +0000 (12:51 +0200)
Replace all occurrences of
  if (VIR_STRDUP(a, b) < 0)
     /* effectively dead code */
with:
  a = g_strdup(b);

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
45 files changed:
src/util/virarptable.c
src/util/virauth.c
src/util/virauthconfig.c
src/util/vircommand.c
src/util/virconf.c
src/util/virdbus.c
src/util/virdnsmasq.c
src/util/virerror.c
src/util/virfcp.c
src/util/virfdstream.c
src/util/virfile.c
src/util/virfilecache.c
src/util/virfirewall.c
src/util/virfirmware.c
src/util/virhostdev.c
src/util/virhostmem.c
src/util/viriscsi.c
src/util/virjson.c
src/util/virlease.c
src/util/virlockspace.c
src/util/virlog.c
src/util/virmdev.c
src/util/virnetdevmacvlan.c
src/util/virnetdevopenvswitch.c
src/util/virnetdevtap.c
src/util/virnetdevvportprofile.c
src/util/virobject.c
src/util/virpci.c
src/util/virportallocator.c
src/util/virresctrl.c
src/util/virrotatingfile.c
src/util/virscsi.c
src/util/virscsivhost.c
src/util/virseclabel.c
src/util/virsecret.c
src/util/virsocketaddr.c
src/util/virstring.c
src/util/virsysinfo.c
src/util/virsystemd.c
src/util/virtypedparam-public.c
src/util/virtypedparam.c
src/util/viruri.c
src/util/virusb.c
src/util/virutil.c
src/util/virxml.c

index cc676a0200372efb5be903294655b2355204afa9..265f60d64533fa57c7511e702954a04a091249e8 100644 (file)
@@ -127,8 +127,7 @@ virArpTableGet(void)
             virAddr.data.inet4.sin_addr = *(struct in_addr *)addr;
             ipstr = virSocketAddrFormat(&virAddr);
 
-            if (VIR_STRDUP(table->t[num].ipaddr, ipstr) < 0)
-                goto cleanup;
+            table->t[num].ipaddr = g_strdup(ipstr);
         }
 
         if (tb[NDA_LLADDR]) {
@@ -140,8 +139,7 @@ virArpTableGet(void)
 
             virMacAddrFormat(&macaddr, ifmac);
 
-            if (VIR_STRDUP(table->t[num].mac, ifmac) < 0)
-                goto cleanup;
+            table->t[num].mac = g_strdup(ifmac);
 
             num++;
         }
index 979cb5773e3f9631ab5a5fd44bec23444a7b1c7b..ddb46cc49841dfc5d34986ad4501d7766fbda18b 100644 (file)
@@ -51,8 +51,7 @@ virAuthGetConfigFilePathURI(virURIPtr uri,
 
     if (authenv) {
         VIR_DEBUG("Using path from env '%s'", authenv);
-        if (VIR_STRDUP(*path, authenv) < 0)
-            return -1;
+        *path = g_strdup(authenv);
         return 0;
     }
 
@@ -61,8 +60,7 @@ virAuthGetConfigFilePathURI(virURIPtr uri,
             if (STREQ_NULLABLE(uri->params[i].name, "authfile") &&
                 uri->params[i].value) {
                 VIR_DEBUG("Using path from URI '%s'", uri->params[i].value);
-                if (VIR_STRDUP(*path, uri->params[i].value) < 0)
-                    return -1;
+                *path = g_strdup(uri->params[i].value);
                 return 0;
             }
         }
@@ -80,8 +78,7 @@ virAuthGetConfigFilePathURI(virURIPtr uri,
 
     VIR_FREE(*path);
 
-    if (VIR_STRDUP(*path, SYSCONFDIR "/libvirt/auth.conf") < 0)
-        return -1;
+    *path = g_strdup(SYSCONFDIR "/libvirt/auth.conf");
 
     VIR_DEBUG("Checking for readability of '%s'", *path);
     if (access(*path, R_OK) == 0)
@@ -129,8 +126,7 @@ virAuthGetCredential(const char *servicename,
                             &tmp) < 0)
         return -1;
 
-    if (VIR_STRDUP(*value, tmp) < 0)
-        return -1;
+    *value = g_strdup(tmp);
 
     return 0;
 }
index 9e55852cd49116b6abbcfce3ae1309685ea8bcd3..6a9001f2d8ba06ec8f8c1abef56aac9412eec8ac 100644 (file)
@@ -44,8 +44,7 @@ virAuthConfigPtr virAuthConfigNew(const char *path)
     if (VIR_ALLOC(auth) < 0)
         goto error;
 
-    if (VIR_STRDUP(auth->path, path) < 0)
-        goto error;
+    auth->path = g_strdup(path);
 
     if (!(auth->keyfile = virKeyFileNew()))
         goto error;
@@ -70,8 +69,7 @@ virAuthConfigPtr virAuthConfigNewData(const char *path,
     if (VIR_ALLOC(auth) < 0)
         goto error;
 
-    if (VIR_STRDUP(auth->path, path) < 0)
-        goto error;
+    auth->path = g_strdup(path);
 
     if (!(auth->keyfile = virKeyFileNew()))
         goto error;
index 93b3dd218fcdd84d692dbbcd7ea3144d66fc29ab..223a2a824e8f9a11522a008767b81773ee239774 100644 (file)
@@ -1061,8 +1061,7 @@ virCommandSetPidFile(virCommandPtr cmd, const char *pidfile)
         return;
 
     VIR_FREE(cmd->pidfile);
-    if (VIR_STRDUP_QUIET(cmd->pidfile, pidfile) < 0)
-        cmd->has_error = ENOMEM;
+    cmd->pidfile = g_strdup(pidfile);
 }
 
 
@@ -1194,8 +1193,7 @@ virCommandSetSELinuxLabel(virCommandPtr cmd,
 
 #if defined(WITH_SECDRIVER_SELINUX)
     VIR_FREE(cmd->seLinuxLabel);
-    if (VIR_STRDUP_QUIET(cmd->seLinuxLabel, label) < 0)
-        cmd->has_error = ENOMEM;
+    cmd->seLinuxLabel = g_strdup(label);
 #endif
     return;
 }
@@ -1219,8 +1217,7 @@ virCommandSetAppArmorProfile(virCommandPtr cmd,
 
 #if defined(WITH_SECDRIVER_APPARMOR)
     VIR_FREE(cmd->appArmorProfile);
-    if (VIR_STRDUP_QUIET(cmd->appArmorProfile, profile) < 0)
-        cmd->has_error = ENOMEM;
+    cmd->appArmorProfile = g_strdup(profile);
 #endif
     return;
 }
@@ -1369,10 +1366,7 @@ virCommandAddEnvString(virCommandPtr cmd, const char *str)
     if (!cmd || cmd->has_error)
         return;
 
-    if (VIR_STRDUP_QUIET(env, str) < 0) {
-        cmd->has_error = ENOMEM;
-        return;
-    }
+    env = g_strdup(str);
 
     virCommandAddEnv(cmd, env);
 }
@@ -1501,10 +1495,7 @@ virCommandAddArg(virCommandPtr cmd, const char *val)
         return;
     }
 
-    if (VIR_STRDUP_QUIET(arg, val) < 0) {
-        cmd->has_error = ENOMEM;
-        return;
-    }
+    arg = g_strdup(val);
 
     /* Arg plus trailing NULL. */
     if (VIR_RESIZE_N(cmd->args, cmd->maxargs, cmd->nargs, 1 + 1) < 0) {
@@ -1542,12 +1533,8 @@ virCommandAddArgBuffer(virCommandPtr cmd, virBufferPtr buf)
     }
 
     cmd->args[cmd->nargs] = virBufferContentAndReset(buf);
-    if (!cmd->args[cmd->nargs]) {
-        if (VIR_STRDUP_QUIET(cmd->args[cmd->nargs], "") < 0) {
-            cmd->has_error = ENOMEM;
-            return;
-        }
-    }
+    if (!cmd->args[cmd->nargs])
+        cmd->args[cmd->nargs] = g_strdup("");
     cmd->nargs++;
 }
 
@@ -1638,10 +1625,7 @@ virCommandAddArgSet(virCommandPtr cmd, const char *const*vals)
     while (vals[narg] != NULL) {
         char *arg;
 
-        if (VIR_STRDUP_QUIET(arg, vals[narg++]) < 0) {
-            cmd->has_error = ENOMEM;
-            return;
-        }
+        arg = g_strdup(vals[narg++]);
         cmd->args[cmd->nargs++] = arg;
     }
 }
@@ -1678,11 +1662,7 @@ virCommandAddArgList(virCommandPtr cmd, ...)
         char *arg = va_arg(list, char *);
         if (!arg)
             break;
-        if (VIR_STRDUP_QUIET(arg, arg) < 0) {
-            cmd->has_error = ENOMEM;
-            va_end(list);
-            return;
-        }
+        arg = g_strdup(arg);
         cmd->args[cmd->nargs++] = arg;
     }
     va_end(list);
@@ -1707,8 +1687,7 @@ virCommandSetWorkingDirectory(virCommandPtr cmd, const char *pwd)
         cmd->has_error = -1;
         VIR_DEBUG("cannot set directory twice");
     } else {
-        if (VIR_STRDUP_QUIET(cmd->pwd, pwd) < 0)
-            cmd->has_error = ENOMEM;
+        cmd->pwd = g_strdup(pwd);
     }
 }
 
@@ -1869,8 +1848,7 @@ virCommandSetInputBuffer(virCommandPtr cmd, const char *inbuf)
         return;
     }
 
-    if (VIR_STRDUP_QUIET(cmd->inbuf, inbuf) < 0)
-        cmd->has_error = ENOMEM;
+    cmd->inbuf = g_strdup(inbuf);
 }
 
 
index 6f7bf3be8eb4222e67a77ad2d84f71a68c82e289..3b678015f5e524baabce2bbdd78bf56718d5523a 100644 (file)
@@ -187,10 +187,7 @@ virConfCreate(const char *filename, unsigned int flags)
     if (!ret)
         return NULL;
 
-    if (VIR_STRDUP(ret->filename, filename) < 0) {
-        VIR_FREE(ret);
-        return NULL;
-    }
+    ret->filename = g_strdup(filename);
 
     ret->flags = flags;
     return ret;
@@ -905,8 +902,7 @@ int virConfGetValueString(virConfPtr conf,
     }
 
     VIR_FREE(*value);
-    if (VIR_STRDUP(*value, cval->str) < 0)
-        return -1;
+    *value = g_strdup(cval->str);
 
     return 1;
 }
@@ -964,24 +960,16 @@ int virConfGetValueStringList(virConfPtr conf,
         if (VIR_ALLOC_N(*values, len + 1) < 0)
             return -1;
 
-        for (len = 0, eval = cval->list; eval; len++, eval = eval->next) {
-            if (VIR_STRDUP((*values)[len], eval->str) < 0) {
-                virStringListFree(*values);
-                *values = NULL;
-                return -1;
-            }
-        }
+        for (len = 0, eval = cval->list; eval; len++, eval = eval->next)
+            (*values)[len] = g_strdup(eval->str);
         break;
 
     case VIR_CONF_STRING:
         if (compatString) {
             if (VIR_ALLOC_N(*values, cval->str ? 2 : 1) < 0)
                 return -1;
-            if (cval->str &&
-                VIR_STRDUP((*values)[0], cval->str) < 0) {
-                VIR_FREE(*values);
-                return -1;
-            }
+            if (cval->str)
+                (*values)[0] = g_strdup(cval->str);
             break;
         }
         G_GNUC_FALLTHROUGH;
@@ -1383,11 +1371,7 @@ virConfSetValue(virConfPtr conf,
             return -1;
         }
         cur->comment = NULL;
-        if (VIR_STRDUP(cur->name, setting) < 0) {
-            virConfFreeValue(value);
-            VIR_FREE(cur);
-            return -1;
-        }
+        cur->name = g_strdup(setting);
         cur->value = value;
         if (prev) {
             cur->next = prev->next;
index f54c917c03e385db28f85dafd07c1e2d1b4cb333..89c9cb3e24f3b2c78125ecf2d57eb1a977bc0dd9 100644 (file)
@@ -1010,8 +1010,7 @@ virDBusMessageIterDecode(DBusMessageIter *rootiter,
                 }
                 char *s;
                 dbus_message_iter_get_basic(iter, &s);
-                if (VIR_STRDUP(*x, s) < 0)
-                    goto cleanup;
+                *x = g_strdup(s);
                 VIR_DEBUG("Read basic type 'char *' varg 'char **'"
                           "' val '%s'", *x);
             } while (0);
@@ -1573,10 +1572,8 @@ virDBusCall(DBusConnection *conn,
             error->level = VIR_ERR_ERROR;
             error->code = VIR_ERR_DBUS_SERVICE;
             error->domain = VIR_FROM_DBUS;
-            if (VIR_STRDUP(error->message, localerror.message) < 0)
-                goto cleanup;
-            if (VIR_STRDUP(error->str1, localerror.name) < 0)
-                goto cleanup;
+            error->message = g_strdup(localerror.message);
+            error->str1 = g_strdup(localerror.name);
             ret = 0;
         } else {
             virReportError(VIR_ERR_DBUS_SERVICE, _("%s: %s"), member,
index 9aeb7b120dbb49c592c93a1cbd739213310f9465..f22250a07e6d2e5420d9be2222046b70767d3d18 100644 (file)
@@ -112,8 +112,7 @@ addnhostsAdd(dnsmasqAddnHostsfile *addnhostsfile,
         if (VIR_ALLOC(addnhostsfile->hosts[idx].hostnames) < 0)
             goto error;
 
-        if (VIR_STRDUP(addnhostsfile->hosts[idx].ip, ipstr) < 0)
-            goto error;
+        addnhostsfile->hosts[idx].ip = g_strdup(ipstr);
 
         addnhostsfile->hosts[idx].nhostnames = 0;
         addnhostsfile->nhosts++;
@@ -122,9 +121,7 @@ addnhostsAdd(dnsmasqAddnHostsfile *addnhostsfile,
     if (VIR_REALLOC_N(addnhostsfile->hosts[idx].hostnames, addnhostsfile->hosts[idx].nhostnames + 1) < 0)
         goto error;
 
-    if (VIR_STRDUP(addnhostsfile->hosts[idx].hostnames[addnhostsfile->hosts[idx].nhostnames],
-                   name) < 0)
-        goto error;
+    addnhostsfile->hosts[idx].hostnames[addnhostsfile->hosts[idx].nhostnames] = g_strdup(name);
 
     VIR_FREE(ipstr);
 
@@ -467,8 +464,7 @@ dnsmasqContextNew(const char *network_name,
     if (VIR_ALLOC(ctx) < 0)
         return NULL;
 
-    if (VIR_STRDUP(ctx->config_dir, config_dir) < 0)
-        goto error;
+    ctx->config_dir = g_strdup(config_dir);
 
     if (!(ctx->hostsfile = hostsfileNew(network_name, config_dir)))
         goto error;
@@ -786,8 +782,7 @@ dnsmasqCapsNewEmpty(const char *binaryPath)
         return NULL;
     if (!(caps->flags = virBitmapNew(DNSMASQ_CAPS_LAST)))
         goto error;
-    if (VIR_STRDUP(caps->binaryPath, binaryPath ? binaryPath : DNSMASQ) < 0)
-        goto error;
+    caps->binaryPath = g_strdup(binaryPath ? binaryPath : DNSMASQ);
     return caps;
 
  error:
index 512b2bc7fecf87bde8267f25e9d9b1cfa78268a9..f0ef7e337ca457873c033cf355fef31b2739fa62 100644 (file)
@@ -207,14 +207,10 @@ virCopyError(virErrorPtr from,
     to->code = from->code;
     to->domain = from->domain;
     to->level = from->level;
-    if (VIR_STRDUP_QUIET(to->message, from->message) < 0)
-        ret = -1;
-    if (VIR_STRDUP_QUIET(to->str1, from->str1) < 0)
-        ret = -1;
-    if (VIR_STRDUP_QUIET(to->str2, from->str2) < 0)
-        ret = -1;
-    if (VIR_STRDUP_QUIET(to->str3, from->str3) < 0)
-        ret = -1;
+    to->message = g_strdup(from->message);
+    to->str1 = g_strdup(from->str1);
+    to->str2 = g_strdup(from->str2);
+    to->str3 = g_strdup(from->str3);
     to->int1 = from->int1;
     to->int2 = from->int2;
     /*
index 2315b517bd3323b8917efeba1ab731f43a0c0408..80773c7c5d4477cdae47ec9b950efecef613da94 100644 (file)
@@ -62,8 +62,7 @@ virFCReadRportValue(const char *rport,
     if ((p = strchr(buf, '\n')))
         *p = '\0';
 
-    if (VIR_STRDUP(*result, buf) < 0)
-        return -1;
+    *result = g_strdup(buf);
 
     return 0;
 }
index 693f1619b3171b861f6503a6fcff4bad82b03efb..719185d99285a9e8ef190dba1e179fdab8401fa1 100644 (file)
@@ -1302,17 +1302,15 @@ virFDStreamOpenFileInternal(virStreamPtr st,
         if ((oflags & O_ACCMODE) == O_RDONLY) {
             threadData->fdin = fd;
             threadData->fdout = pipefds[1];
-            if (VIR_STRDUP(threadData->fdinname, path) < 0 ||
-                VIR_STRDUP(threadData->fdoutname, "pipe") < 0)
-                goto error;
+            threadData->fdinname = g_strdup(path);
+            threadData->fdoutname = g_strdup("pipe");
             tmpfd = pipefds[0];
             threadData->doRead = true;
         } else {
             threadData->fdin = pipefds[0];
             threadData->fdout = fd;
-            if (VIR_STRDUP(threadData->fdinname, "pipe") < 0 ||
-                VIR_STRDUP(threadData->fdoutname, path) < 0)
-                goto error;
+            threadData->fdinname = g_strdup("pipe");
+            threadData->fdoutname = g_strdup(path);
             tmpfd = pipefds[1];
             threadData->doRead = false;
         }
index 6a26d4838c3e7e74ac2f3ddb310f26594579e6c4..c4d544be73a7521c9ab28738579af6d2315e9308 100644 (file)
@@ -1578,8 +1578,10 @@ virFileResolveLinkHelper(const char *linkpath,
         if (lstat(linkpath, &st) < 0)
             return -1;
 
-        if (!S_ISLNK(st.st_mode))
-            return VIR_STRDUP_QUIET(*resultpath, linkpath) < 0 ? -1 : 0;
+        if (!S_ISLNK(st.st_mode)) {
+            *resultpath = g_strdup(linkpath);
+            return 0;
+        }
     }
 
     *resultpath = virFileCanonicalizePath(linkpath);
@@ -1684,9 +1686,7 @@ virFindFileInPath(const char *file)
     origpath = getenv("PATH");
     if (!origpath)
         origpath = "/bin:/usr/bin";
-
-    if (VIR_STRDUP_QUIET(path, origpath) <= 0)
-        return NULL;
+    path = g_strdup(origpath);
 
     /* for each path segment, append the file to search for and test for
      * it. return it if found.
@@ -2023,8 +2023,7 @@ virFileGetMountSubtreeImpl(const char *mtabpath,
 
         if (VIR_EXPAND_N(mounts, nmounts, nmounts ? 1 : 2) < 0)
             goto cleanup;
-        if (VIR_STRDUP(mounts[nmounts - 2], mntent.mnt_dir) < 0)
-            goto cleanup;
+        mounts[nmounts - 2] = g_strdup(mntent.mnt_dir);
     }
 
     if (mounts)
@@ -3070,10 +3069,7 @@ virFileMakePathWithMode(const char *path,
 {
     g_autofree char *tmp = NULL;
 
-    if (VIR_STRDUP(tmp, path) < 0) {
-        errno = ENOMEM;
-        return -1;
-    }
+    tmp = g_strdup(path);
 
     return virFileMakePathHelper(tmp, mode);
 }
@@ -3087,10 +3083,7 @@ virFileMakeParentPath(const char *path)
 
     VIR_DEBUG("path=%s", path);
 
-    if (VIR_STRDUP(tmp, path) < 0) {
-        errno = ENOMEM;
-        return -1;
-    }
+    tmp = g_strdup(path);
 
     if ((p = strrchr(tmp, '/')) == NULL) {
         errno = EINVAL;
@@ -3293,8 +3286,7 @@ int
 virFileAbsPath(const char *path, char **abspath)
 {
     if (path[0] == '/') {
-        if (VIR_STRDUP(*abspath, path) < 0)
-            return -1;
+        *abspath = g_strdup(path);
     } else {
         g_autofree char *buf = getcwd(NULL, 0);
 
@@ -3317,8 +3309,7 @@ virFileSanitizePath(const char *path)
     char *cleanpath;
     int idx = 0;
 
-    if (VIR_STRDUP(cleanpath, path) < 0)
-        return NULL;
+    cleanpath = g_strdup(path);
 
     /* don't sanitize URIs - rfc3986 states that two slashes may lead to a
      * different resource, thus removing them would possibly change the path */
@@ -3504,9 +3495,8 @@ virFileIsSharedFixFUSE(const char *path,
             maxMatching = len;
             VIR_FREE(mntType);
             VIR_FREE(mntDir);
-            if (VIR_STRDUP(mntDir, mb.mnt_dir) < 0 ||
-                VIR_STRDUP(mntType, mb.mnt_type) < 0)
-                goto cleanup;
+            mntDir = g_strdup(mb.mnt_dir);
+            mntType = g_strdup(mb.mnt_type);
         }
     }
 
@@ -3540,8 +3530,7 @@ virFileIsSharedFSType(const char *path,
     int statfs_ret;
     long long f_type = 0;
 
-    if (VIR_STRDUP(dirpath, path) < 0)
-        return -1;
+    dirpath = g_strdup(path);
 
     statfs_ret = statfs(dirpath, &sb);
 
@@ -3712,8 +3701,7 @@ virFileFindHugeTLBFS(virHugeTLBFSPtr *ret_fs,
 
         tmp = &fs[nfs - 1];
 
-        if (VIR_STRDUP(tmp->mnt_dir, mb.mnt_dir) < 0)
-            goto cleanup;
+        tmp->mnt_dir = g_strdup(mb.mnt_dir);
 
         if (virFileGetHugepageSize(tmp->mnt_dir, &tmp->size) < 0)
             goto cleanup;
index 3a99dc210b303283d64a6a157596df0452dc10ab..8ab37bae4ae75a708b8ba59ccf131122f67f474a 100644 (file)
@@ -245,11 +245,9 @@ virFileCacheNew(const char *dir,
     if (!(cache->table = virHashCreate(10, virObjectFreeHashData)))
         goto cleanup;
 
-    if (VIR_STRDUP(cache->dir, dir) < 0)
-        goto cleanup;
+    cache->dir = g_strdup(dir);
 
-    if (VIR_STRDUP(cache->suffix, suffix) < 0)
-        goto cleanup;
+    cache->suffix = g_strdup(suffix);
 
     cache->handlers = *handlers;
 
index c2e88ec38221b337c1f62c72973e3b2a420d2955..fc2c7248cb0c712b1d05e35256c41224b8328520 100644 (file)
@@ -323,8 +323,7 @@ void virFirewallFree(virFirewallPtr firewall)
                          rule->argsLen, 1) < 0) \
             goto no_memory; \
  \
-        if (VIR_STRDUP(rule->args[rule->argsLen++], str) < 0) \
-            goto no_memory; \
+        rule->args[rule->argsLen++] = g_strdup(str); \
     } while (0)
 
 static virFirewallRulePtr
index b4747bd3460b3a7e2be40e6c0ff95bc110cbf6dc..9a0610c6478018d6762c7bd63733da8995de5500 100644 (file)
@@ -79,9 +79,8 @@ virFirmwareParse(const char *str, virFirmwarePtr firmware)
         goto cleanup;
     }
 
-    if (VIR_STRDUP(firmware->name, token[0]) < 0 ||
-        VIR_STRDUP(firmware->nvram, token[1]) < 0)
-        goto cleanup;
+    firmware->name = g_strdup(token[0]);
+    firmware->nvram = g_strdup(token[1]);
 
     ret = 0;
  cleanup:
@@ -122,9 +121,8 @@ virFirmwareParseList(const char *list,
 
             if (VIR_ALLOC(fws[j]) < 0)
                 goto cleanup;
-            if (VIR_STRDUP(fws[j]->name, token[2 * j]) < 0 ||
-                VIR_STRDUP(fws[j]->nvram, token[2 * j + 1]) < 0)
-                goto cleanup;
+            fws[j]->name = g_strdup(token[2 * j]);
+            fws[j]->nvram = g_strdup(token[2 * j + 1]);
         }
     }
 
index 6b29bb1a736392460644f5c511d8315588fc9124..6633b48805ea05098f2126e84ba67e3b782084c4 100644 (file)
@@ -169,8 +169,7 @@ virHostdevManagerNew(void)
         return NULL;
 
     if (privileged) {
-        if (VIR_STRDUP(hostdevMgr->stateDir, HOSTDEV_STATE_DIR) < 0)
-            return NULL;
+        hostdevMgr->stateDir = g_strdup(HOSTDEV_STATE_DIR);
 
         if (virFileMakePath(hostdevMgr->stateDir) < 0) {
             virReportError(VIR_ERR_OPERATION_FAILED,
index 938e2fa6b31c5035b4ef6d1e78328fdb63d72d5d..c1dfc1225c4c976dd400973ed9711f4b3d1d5be2 100644 (file)
@@ -268,8 +268,7 @@ virHostMemGetStats(int cellNum G_GNUC_UNUSED,
             cellNum = VIR_NODE_MEMORY_STATS_ALL_CELLS;
 
         if (cellNum == VIR_NODE_MEMORY_STATS_ALL_CELLS) {
-            if (VIR_STRDUP(meminfo_path, MEMINFO_PATH) < 0)
-                return -1;
+            meminfo_path = g_strdup(MEMINFO_PATH);
         } else {
             if ((max_node = virNumaGetMaxNode()) < 0)
                 return -1;
index 1b143ec61f3442d5f68b530414195f667ce58899..ba90c4176318cc639feb4b9852e4698516bdfcd5 100644 (file)
@@ -176,8 +176,7 @@ virStorageBackendIQNFound(const char *initiatoriqn,
             current = next + 1;
         }
 
-        if (VIR_STRDUP(iqn, current) < 0)
-            goto cleanup;
+        iqn = g_strdup(current);
 
         if (STREQ(iqn, initiatoriqn)) {
             *ifacename = g_steal_pointer(&iface);
@@ -373,8 +372,7 @@ virISCSIGetTargets(char **const groups,
     struct virISCSITargetList *list = data;
     g_autofree char *target = NULL;
 
-    if (VIR_STRDUP(target, groups[1]) < 0)
-        return -1;
+    target = g_strdup(groups[1]);
 
     if (VIR_APPEND_ELEMENT(list->targets, list->ntargets, target) < 0)
         return -1;
index d3e6c9e41d2c034b684c8e30075e4578ab78034f..eb6207f13f60a6276cb6f5a0cdfcc959f16f4f0f 100644 (file)
@@ -450,10 +450,7 @@ virJSONValueNewString(const char *data)
         return NULL;
 
     val->type = VIR_JSON_TYPE_STRING;
-    if (VIR_STRDUP(val->data.string, data) < 0) {
-        VIR_FREE(val);
-        return NULL;
-    }
+    val->data.string = g_strdup(data);
 
     return val;
 }
@@ -490,10 +487,7 @@ virJSONValueNewNumber(const char *data)
         return NULL;
 
     val->type = VIR_JSON_TYPE_NUMBER;
-    if (VIR_STRDUP(val->data.number, data) < 0) {
-        VIR_FREE(val);
-        return NULL;
-    }
+    val->data.number = g_strdup(data);
 
     return val;
 }
@@ -626,8 +620,7 @@ virJSONValueObjectInsert(virJSONValuePtr object,
         return -1;
     }
 
-    if (VIR_STRDUP(pair.key, key) < 0)
-        return -1;
+    pair.key = g_strdup(key);
 
     if (prepend) {
         ret = VIR_INSERT_ELEMENT(object->data.object.pairs, 0,
index 3d851eb808f7d9b8430f6e9bb434fd9fb1846dfa..e0f81539bede09b4eda29d7b3eae0de9f8e4b2ff 100644 (file)
@@ -221,8 +221,7 @@ virLeaseNew(virJSONValuePtr *lease_ret,
         return 0;
 
     if (exptime_tmp) {
-        if (VIR_STRDUP(exptime, exptime_tmp) < 0)
-            return -1;
+        exptime = g_strdup(exptime_tmp);
 
         /* Removed extraneous trailing space in DNSMASQ_LEASE_EXPIRES
          * (dnsmasq < 2.52) */
index d3837461834d84ec34e841c1d15781079dc88e65..b0f73c2a8a612550630b1060b63c09404d1a96e1 100644 (file)
@@ -127,8 +127,7 @@ virLockSpaceResourceNew(virLockSpacePtr lockspace,
     res->fd = -1;
     res->flags = flags;
 
-    if (VIR_STRDUP(res->name, resname) < 0)
-        goto error;
+    res->name = g_strdup(resname);
 
     if (!(res->path = virLockSpaceGetResourcePath(lockspace, resname)))
         goto error;
@@ -255,8 +254,7 @@ virLockSpacePtr virLockSpaceNew(const char *directory)
         return NULL;
     }
 
-    if (VIR_STRDUP(lockspace->dir, directory) < 0)
-        goto error;
+    lockspace->dir = g_strdup(directory);
 
     if (!(lockspace->resources = virHashCreate(VIR_LOCKSPACE_TABLE_SIZE,
                                                virLockSpaceResourceDataFree)))
@@ -313,8 +311,7 @@ virLockSpacePtr virLockSpaceNewPostExecRestart(virJSONValuePtr object)
 
     if (virJSONValueObjectHasKey(object, "directory")) {
         const char *dir = virJSONValueObjectGetString(object, "directory");
-        if (VIR_STRDUP(lockspace->dir, dir) < 0)
-            goto error;
+        lockspace->dir = g_strdup(dir);
     }
 
     if (!(resources = virJSONValueObjectGet(object, "resources"))) {
@@ -347,10 +344,7 @@ virLockSpacePtr virLockSpaceNewPostExecRestart(virJSONValuePtr object)
             virLockSpaceResourceFree(res);
             goto error;
         }
-        if (VIR_STRDUP(res->name, tmp) < 0) {
-            virLockSpaceResourceFree(res);
-            goto error;
-        }
+        res->name = g_strdup(tmp);
 
         if (!(tmp = virJSONValueObjectGetString(child, "path"))) {
             virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@@ -358,10 +352,7 @@ virLockSpacePtr virLockSpaceNewPostExecRestart(virJSONValuePtr object)
             virLockSpaceResourceFree(res);
             goto error;
         }
-        if (VIR_STRDUP(res->path, tmp) < 0) {
-            virLockSpaceResourceFree(res);
-            goto error;
-        }
+        res->path = g_strdup(tmp);
         if (virJSONValueObjectGetNumberInt(child, "fd", &res->fd) < 0) {
             virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                            _("Missing resource fd in JSON document"));
index 2ce094f6aaad50dbb1bb79bff7c0fb7aa39f69d5..27843363e7e5070269e8f5f3eb7cd0fc9febee43 100644 (file)
@@ -840,8 +840,7 @@ virLogNewOutputToSyslog(virLogPriority priority,
          * rather than copying @ident, syslog uses caller's reference instead
          */
         VIR_FREE(current_ident);
-        if (VIR_STRDUP(current_ident, ident) < 0)
-            return NULL;
+        current_ident = g_strdup(ident);
 
         openlog(current_ident, 0, 0);
     }
@@ -1331,8 +1330,7 @@ virLogOutputNew(virLogOutputFunc f,
             return NULL;
         }
 
-        if (VIR_STRDUP(ndup, name) < 0)
-            return NULL;
+        ndup = g_strdup(name);
     }
 
     if (VIR_ALLOC(ret) < 0) {
@@ -1466,10 +1464,7 @@ virLogDefineOutputs(virLogOutputPtr *outputs, size_t noutputs)
          * holding the lock so it's safe to call openlog and change the message
          * tag
          */
-        if (VIR_STRDUP_QUIET(tmp, outputs[id]->name) < 0) {
-            virLogUnlock();
-            return -1;
-        }
+        tmp = g_strdup(outputs[id]->name);
         VIR_FREE(current_ident);
         current_ident = tmp;
         openlog(current_ident, 0, 0);
index 7e70ceb658606e6afdffc1cdaf0ff76e96b6f982..9f8cb954238d146f825cedc1174f5a12498bb6ff 100644 (file)
@@ -271,10 +271,8 @@ virMediatedDeviceSetUsedBy(virMediatedDevicePtr dev,
 {
     VIR_FREE(dev->used_by_drvname);
     VIR_FREE(dev->used_by_domname);
-    if (VIR_STRDUP(dev->used_by_drvname, drvname) < 0)
-        return -1;
-    if (VIR_STRDUP(dev->used_by_domname, domname) < 0)
-        return -1;
+    dev->used_by_drvname = g_strdup(drvname);
+    dev->used_by_domname = g_strdup(domname);
 
     return 0;
 }
@@ -509,8 +507,7 @@ virMediatedDeviceTypeReadAttrs(const char *sysfspath,
     if (VIR_ALLOC(tmp) < 0)
         return -1;
 
-    if (VIR_STRDUP(tmp->id, last_component(sysfspath)) < 0)
-        return -1;
+    tmp->id = g_strdup(last_component(sysfspath));
 
     /* @name sysfs attribute is optional, so getting ENOENT is fine */
     MDEV_GET_SYSFS_ATTR("name", &tmp->name, virFileReadValueString, true);
index 4c388b6c554b3fdc202577582e9a65d382105618..2ccd83d1bb15df47df9f438fe4e488a030ce422a 100644 (file)
@@ -836,14 +836,12 @@ virNetDevMacVLanVPortProfileRegisterCallback(const char *ifname,
     if (virtPortProfile && virNetlinkEventServiceIsRunning(NETLINK_ROUTE)) {
         if (VIR_ALLOC(calld) < 0)
             goto error;
-        if (VIR_STRDUP(calld->cr_ifname, ifname) < 0)
-            goto error;
+        calld->cr_ifname = g_strdup(ifname);
         if (VIR_ALLOC(calld->virtPortProfile) < 0)
             goto error;
         memcpy(calld->virtPortProfile, virtPortProfile, sizeof(*virtPortProfile));
         virMacAddrSet(&calld->macaddress, macaddress);
-        if (VIR_STRDUP(calld->linkdev, linkdev) < 0)
-            goto error;
+        calld->linkdev = g_strdup(linkdev);
         memcpy(calld->vmuuid, vmuuid, sizeof(calld->vmuuid));
 
         calld->vmOp = vmOp;
@@ -1044,11 +1042,9 @@ virNetDevMacVLanCreateWithVPortProfile(const char *ifnameRequested,
         if (virNetDevMacVLanTapSetup(tapfd, tapfdSize, vnet_hdr) < 0)
             goto disassociate_exit;
 
-        if (VIR_STRDUP(*ifnameResult, ifnameCreated) < 0)
-            goto disassociate_exit;
+        *ifnameResult = g_strdup(ifnameCreated);
     } else {
-        if (VIR_STRDUP(*ifnameResult, ifnameCreated) < 0)
-            goto disassociate_exit;
+        *ifnameResult = g_strdup(ifnameCreated);
     }
 
     if (vmOp == VIR_NETDEV_VPORT_PROFILE_OP_CREATE ||
index 6e13c0f684398f5f2c5aab09f22598fd560e8e19..1d2bbf9dd75e92f9e9d4702b07de77935d7618db 100644 (file)
@@ -529,8 +529,7 @@ virNetDevOpenvswitchGetVhostuserIfname(const char *path,
         goto cleanup;
     }
 
-    if (VIR_STRDUP(*ifname, tmpIfname) < 0)
-        goto cleanup;
+    *ifname = g_strdup(tmpIfname);
     ret = 1;
 
  cleanup:
index 8ca4626a902da84bf242a03c6dde05f5eb2de80a..fe4f55f8fcc160272dabccf51e67d1e4031324f1 100644 (file)
@@ -73,7 +73,8 @@ virNetDevTapGetName(int tapfd G_GNUC_UNUSED, char **ifname G_GNUC_UNUSED)
         return -1;
     }
 
-    return VIR_STRDUP(*ifname, ifr.ifr_name) < 0 ? -1 : 0;
+    *ifname = g_strdup(ifr.ifr_name);
+    return 0;
 #else
     return -1;
 #endif
@@ -282,8 +283,7 @@ int virNetDevTapCreate(char **ifname,
             /* In case we are looping more than once, set other
              * TAPs to have the same name */
             VIR_FREE(*ifname);
-            if (VIR_STRDUP(*ifname, ifr.ifr_name) < 0)
-                goto cleanup;
+            *ifname = g_strdup(ifr.ifr_name);
         }
 
         if ((flags & VIR_NETDEV_TAP_CREATE_PERSIST) &&
index b001aea3ec19562b98f9b122e4d0bc92c161d5e3..6442c2a2cfa3d5fbcc7ed63be4fe70d637724a11 100644 (file)
@@ -1145,10 +1145,7 @@ virNetDevVPortProfileOp8021Qbh(const char *ifname,
             goto cleanup;
         }
     } else {
-        if (VIR_STRDUP(physfndev, ifname) < 0) {
-            rc = -1;
-            goto cleanup;
-        }
+        physfndev = g_strdup(ifname);
     }
 
     rc = virNetDevGetIndex(physfndev, &ifindex);
index c5363308d878ed8f72c1aabbe944d0018bb8e675..812b013e722c8e27a8e1be3031dae5c1733f912b 100644 (file)
@@ -188,8 +188,7 @@ virClassNew(virClassPtr parent,
                        _("too many object classes defined"));
         goto error;
     }
-    if (VIR_STRDUP(klass->name, name) < 0)
-        goto error;
+    klass->name = g_strdup(name);
     klass->objectSize = objectSize;
     klass->dispose = dispose;
 
index 59a93a5e81b0980b3b8530c19806d523bfd2741e..f9e39e79d84b7c41fce874685c43352a911341fe 100644 (file)
@@ -265,8 +265,7 @@ virPCIDeviceGetDriverPathAndName(virPCIDevicePtr dev, char **path, char **name)
     }
     /* path = "/sys/bus/pci/drivers/${drivername}" */
 
-    if (VIR_STRDUP(*name, last_component(*path)) < 0)
-        goto cleanup;
+    *name = g_strdup(last_component(*path));
     /* name = "${drivername}" */
 
     ret = 0;
@@ -1435,17 +1434,11 @@ virPCIDeviceCopy(virPCIDevicePtr dev)
     *copy = *dev;
     copy->path = NULL;
     copy->used_by_drvname = copy->used_by_domname = NULL;
-    if (VIR_STRDUP(copy->name, dev->name) < 0 ||
-        VIR_STRDUP(copy->path, dev->path) < 0 ||
-        VIR_STRDUP(copy->used_by_drvname, dev->used_by_drvname) < 0 ||
-        VIR_STRDUP(copy->used_by_domname, dev->used_by_domname) < 0) {
-        goto error;
-    }
+    copy->name = g_strdup(dev->name);
+    copy->path = g_strdup(dev->path);
+    copy->used_by_drvname = g_strdup(dev->used_by_drvname);
+    copy->used_by_domname = g_strdup(dev->used_by_domname);
     return copy;
-
- error:
-    virPCIDeviceFree(copy);
-    return NULL;
 }
 
 
@@ -1561,10 +1554,8 @@ virPCIDeviceSetUsedBy(virPCIDevicePtr dev,
 {
     VIR_FREE(dev->used_by_drvname);
     VIR_FREE(dev->used_by_domname);
-    if (VIR_STRDUP(dev->used_by_drvname, drv_name) < 0)
-        return -1;
-    if (VIR_STRDUP(dev->used_by_domname, dom_name) < 0)
-        return -1;
+    dev->used_by_drvname = g_strdup(drv_name);
+    dev->used_by_domname = g_strdup(dom_name);
 
     return 0;
 }
@@ -2503,8 +2494,7 @@ virPCIGetNetName(const char *device_link_sysfs_path,
                 continue;
         }
 
-        if (VIR_STRDUP(*netname, entry->d_name) < 0)
-            goto cleanup;
+        *netname = g_strdup(entry->d_name);
 
         ret = 0;
         break;
index 1ffd446f40b2c1bfb5bc85db566fe5707a76d5cf..494bf9107a14d2af6e9ae0df852150aa3b7cd85b 100644 (file)
@@ -111,15 +111,9 @@ virPortAllocatorRangeNew(const char *name,
 
     range->start = start;
     range->end = end;
-
-    if (VIR_STRDUP(range->name, name) < 0)
-        goto error;
+    range->name = g_strdup(name);
 
     return range;
-
- error:
-    virPortAllocatorRangeFree(range);
-    return NULL;
 }
 
 void
index e52408ed06d2c1e96d70746d636a60b8eb55f930..29ea52a16f673bf14947df3f37089ca6959e591a 100644 (file)
@@ -2339,8 +2339,7 @@ virResctrlAllocDeterminePath(virResctrlAllocPtr alloc,
 
     /* If the allocation is empty, then the path will be SYSFS_RESCTRL_PATH */
     if (virResctrlAllocIsEmpty(alloc)) {
-        if (VIR_STRDUP(alloc->path, SYSFS_RESCTRL_PATH) < 0)
-            return -1;
+        alloc->path = g_strdup(SYSFS_RESCTRL_PATH);
 
         return 0;
     }
@@ -2563,8 +2562,7 @@ virResctrlMonitorDeterminePath(virResctrlMonitorPtr monitor,
 
     if (!virResctrlAllocIsEmpty(monitor->alloc) &&
         STREQ_NULLABLE(monitor->id, monitor->alloc->id)) {
-        if (VIR_STRDUP(monitor->path, monitor->alloc->path) < 0)
-            return -1;
+        monitor->path = g_strdup(monitor->alloc->path);
         return 0;
     }
 
index 1171d3b153926ee587eb8d5c3d21a05e11f7b8e8..82a677b743991d93ec915dc807ae79539856d899 100644 (file)
@@ -170,8 +170,7 @@ virRotatingFileReaderEntryNew(const char *path)
         entry->inode = sb.st_ino;
     }
 
-    if (VIR_STRDUP(entry->path, path) < 0)
-        goto error;
+    entry->path = g_strdup(path);
 
     return entry;
 
@@ -243,8 +242,7 @@ virRotatingFileWriterNew(const char *path,
     if (VIR_ALLOC(file) < 0)
         goto error;
 
-    if (VIR_STRDUP(file->basepath, path) < 0)
-        goto error;
+    file->basepath = g_strdup(path);
 
     if (maxbackup > VIR_MAX_MAX_BACKUP) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
@@ -389,8 +387,7 @@ virRotatingFileWriterRollover(virRotatingFileWriterPtr file)
 
         for (i = file->maxbackup; i > 0; i--) {
             if (i == 1) {
-                if (VIR_STRDUP(thispath, file->basepath) < 0)
-                    goto cleanup;
+                thispath = g_strdup(file->basepath);
             } else {
                 if (virAsprintf(&thispath, "%s.%zu", file->basepath, i - 2) < 0)
                     goto cleanup;
index af8692eb5b44e867f898395633e752ff7a5863fa..705571f8ec55a1d8c48fe1e8792c9425e488d72a 100644 (file)
@@ -277,9 +277,8 @@ virSCSIDeviceSetUsedBy(virSCSIDevicePtr dev,
 
     if (VIR_ALLOC(copy) < 0)
         return -1;
-    if (VIR_STRDUP(copy->drvname, drvname) < 0 ||
-        VIR_STRDUP(copy->domname, domname) < 0)
-        return -1;
+    copy->drvname = g_strdup(drvname);
+    copy->domname = g_strdup(domname);
 
     if (VIR_APPEND_ELEMENT(dev->used_by, dev->n_used_by, copy) < 0)
         return -1;
index 0bcd8902a4b62db31d104217f2658b67b6fe919d..5f523636bec585123ed3121996e324550920f69e 100644 (file)
@@ -205,10 +205,8 @@ virSCSIVHostDeviceSetUsedBy(virSCSIVHostDevicePtr dev,
 {
     VIR_FREE(dev->used_by_drvname);
     VIR_FREE(dev->used_by_domname);
-    if (VIR_STRDUP(dev->used_by_drvname, drvname) < 0)
-        return -1;
-    if (VIR_STRDUP(dev->used_by_domname, domname) < 0)
-        return -1;
+    dev->used_by_drvname = g_strdup(drvname);
+    dev->used_by_domname = g_strdup(domname);
 
     return 0;
 }
@@ -256,12 +254,7 @@ virSCSIVHostDeviceNew(const char *name)
     if (VIR_ALLOC(dev) < 0)
         return NULL;
 
-    if (VIR_STRDUP(dev->name, name) < 0) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("dev->name buffer overflow: %s"),
-                       name);
-        return NULL;
-    }
+    dev->name = g_strdup(name);
 
     if (virAsprintf(&dev->path, "%s/%s",
                     SYSFS_VHOST_SCSI_DEVICES, name) < 0)
index 02a834223d2ec2a5f22eeb556593bcd706c61ea3..a2b5ebf6b7eaa473f93486e95d8888c143d2aabf 100644 (file)
@@ -58,12 +58,13 @@ virSecurityLabelDefNew(const char *model)
 {
     virSecurityLabelDefPtr seclabel = NULL;
 
-    if (VIR_ALLOC(seclabel) < 0 ||
-        VIR_STRDUP(seclabel->model, model) < 0) {
+    if (VIR_ALLOC(seclabel) < 0) {
         virSecurityLabelDefFree(seclabel);
         return NULL;
     }
 
+    seclabel->model = g_strdup(model);
+
     seclabel->relabel = true;
 
     return seclabel;
@@ -74,12 +75,13 @@ virSecurityDeviceLabelDefNew(const char *model)
 {
     virSecurityDeviceLabelDefPtr seclabel = NULL;
 
-    if (VIR_ALLOC(seclabel) < 0 ||
-        VIR_STRDUP(seclabel->model, model) < 0) {
+    if (VIR_ALLOC(seclabel) < 0) {
         virSecurityDeviceLabelDefFree(seclabel);
         seclabel = NULL;
     }
 
+    seclabel->model = g_strdup(model);
+
     return seclabel;
 }
 
@@ -95,13 +97,8 @@ virSecurityDeviceLabelDefCopy(const virSecurityDeviceLabelDef *src)
     ret->relabel = src->relabel;
     ret->labelskip = src->labelskip;
 
-    if (VIR_STRDUP(ret->model, src->model) < 0 ||
-        VIR_STRDUP(ret->label, src->label) < 0)
-        goto error;
+    ret->model = g_strdup(src->model);
+    ret->label = g_strdup(src->label);
 
     return ret;
-
- error:
-    virSecurityDeviceLabelDefFree(ret);
-    return NULL;
 }
index 7844a76a56c4a9e9b08234aee0d1b303e8472955..174ce544c0fbb1cf5c61ca335aee9def9aabbbec 100644 (file)
@@ -55,8 +55,7 @@ virSecretLookupDefCopy(virSecretLookupTypeDefPtr dst,
     if (dst->type == VIR_SECRET_LOOKUP_TYPE_UUID) {
         memcpy(dst->u.uuid, src->u.uuid, VIR_UUID_BUFLEN);
     } else if (dst->type == VIR_SECRET_LOOKUP_TYPE_USAGE) {
-        if (VIR_STRDUP(dst->u.usage, src->u.usage) < 0)
-            return -1;
+        dst->u.usage = g_strdup(src->u.usage);
     }
     return 0;
 }
index 91e2a8d55819baf83f7e8ec962419cffc334c227..efe942b44c459eab2c5cc13a4b31ecebfc08cf58 100644 (file)
@@ -481,8 +481,7 @@ virSocketAddrFormatFull(const virSocketAddr *addr,
                             separator ? separator : ":") < 0)
                 return NULL;
         } else {
-            if (VIR_STRDUP(addrstr, VIR_LOOPBACK_IPV4_ADDR) < 0)
-                return NULL;
+            addrstr = g_strdup(VIR_LOOPBACK_IPV4_ADDR);
         }
         return addrstr;
     }
@@ -515,8 +514,7 @@ virSocketAddrFormatFull(const virSocketAddr *addr,
             return NULL;
         }
     } else {
-        if (VIR_STRDUP(addrstr, host) < 0)
-            return NULL;
+        addrstr = g_strdup(host);
     }
 
     return addrstr;
index fcae16c8feb7786c1fa82036b4e4fbd337eb5015..1494eab13298ba17d7dd6295e0336e5291a2a30d 100644 (file)
@@ -102,8 +102,7 @@ virStringSplitCount(const char *string,
         if (VIR_RESIZE_N(tokens, maxtokens, ntokens, 1) < 0)
             goto error;
 
-        if (VIR_STRDUP(tokens[ntokens], remainder) < 0)
-            goto error;
+        tokens[ntokens] = g_strdup(remainder);
         ntokens++;
     }
 
@@ -182,10 +181,11 @@ virStringListAdd(char ***strings,
 {
     size_t i = virStringListLength((const char **) *strings);
 
-    if (VIR_EXPAND_N(*strings, i, 2) < 0 ||
-        VIR_STRDUP((*strings)[i - 2], item) < 0)
+    if (VIR_EXPAND_N(*strings, i, 2) < 0)
         return -1;
 
+    (*strings)[i - 2] = g_strdup(item);
+
     return 0;
 }
 
@@ -286,10 +286,8 @@ virStringListCopy(char ***dst,
     if (VIR_ALLOC_N(copy, virStringListLength(src) + 1) < 0)
         goto error;
 
-    for (i = 0; src[i]; i++) {
-        if (VIR_STRDUP(copy[i], src[i]) < 0)
-            goto error;
-    }
+    for (i = 0; src[i]; i++)
+        copy[i] = g_strdup(src[i]);
 
     *dst = copy;
     return 0;
index af26e0bab953d4425c104f014a54ddd49e652932..0a622dbbf93d1f0b0327f456c1acdab3fde173b0 100644 (file)
@@ -420,8 +420,7 @@ virSysinfoParseARMProcessor(const char *base, virSysinfoDefPtr ret)
                         cur, eol - cur) < 0)
             goto error;
 
-        if (VIR_STRDUP(processor->processor_type, processor_type) < 0)
-            goto error;
+        processor->processor_type = g_strdup(processor_type);
 
         base = cur;
     }
@@ -558,8 +557,7 @@ virSysinfoParseS390Processor(const char *base, virSysinfoDefPtr ret)
         if (VIR_EXPAND_N(ret->processor, ret->nprocessor, 1) < 0)
             goto error;
         processor = &ret->processor[ret->nprocessor - 1];
-        if (VIR_STRDUP(processor->processor_manufacturer, manufacturer) < 0)
-            goto error;
+        processor->processor_manufacturer = g_strdup(manufacturer);
         if (!virSysinfoParseS390Delimited(procline, "version",
                                           &processor->processor_version,
                                           '=', ',') ||
index c2e4c3df5180065904b2a3ff3d495038f116b493..2ff0341b1138343a4bb4242d9d09a936e043f979 100644 (file)
@@ -308,8 +308,7 @@ int virSystemdCreateMachine(const char *name,
         if (!(slicename = virSystemdMakeSliceName(partition)))
              goto cleanup;
     } else {
-        if (VIR_STRDUP(slicename, "") < 0)
-            goto cleanup;
+        slicename = g_strdup("");
     }
 
     /*
index eaa9f433e720d9a4fdcf28a518ed169e7f7a9425..0ddb618dbff3a2663ee9a39cc58ff8e9e269f5d1 100644 (file)
@@ -104,8 +104,7 @@ virTypedParameterAssignFromStr(virTypedParameterPtr param,
         }
         break;
     case VIR_TYPED_PARAM_STRING:
-        if (VIR_STRDUP(param->value.s, val) < 0)
-            return -1;
+        param->value.s = g_strdup(val);
         break;
     default:
         virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -736,8 +735,7 @@ virTypedParamsAddString(virTypedParameterPtr *params,
         goto error;
     *maxparams = max;
 
-    if (VIR_STRDUP(str, value) < 0)
-        goto error;
+    str = g_strdup(value);
 
     if (virTypedParameterAssign(*params + n, name,
                                 VIR_TYPED_PARAM_STRING, str) < 0) {
index db440611dc73f70b087335db879b1d00195b2390..f50d926860f41fc7c3692ffe48d96f32467396ae 100644 (file)
@@ -234,8 +234,7 @@ virTypedParameterAssignValueVArgs(virTypedParameterPtr param,
         break;
     case VIR_TYPED_PARAM_STRING:
         if (copystr) {
-            if (VIR_STRDUP(param->value.s, va_arg(ap, char *)) < 0)
-                return -1;
+            param->value.s = g_strdup(va_arg(ap, char *));
         } else {
             param->value.s = va_arg(ap, char *);
         }
@@ -337,8 +336,7 @@ virTypedParamsReplaceString(virTypedParameterPtr *params,
         param = *params + n - 1;
     }
 
-    if (VIR_STRDUP(str, value) < 0)
-        goto error;
+    str = g_strdup(value);
 
     if (virTypedParameterAssign(param, name,
                                 VIR_TYPED_PARAM_STRING, str) < 0) {
@@ -374,11 +372,7 @@ virTypedParamsCopy(virTypedParameterPtr *dst,
         ignore_value(virStrcpyStatic((*dst)[i].field, src[i].field));
         (*dst)[i].type = src[i].type;
         if (src[i].type == VIR_TYPED_PARAM_STRING) {
-            if (VIR_STRDUP((*dst)[i].value.s, src[i].value.s) < 0) {
-                virTypedParamsFree(*dst, i - 1);
-                *dst = NULL;
-                return -1;
-            }
+            (*dst)[i].value.s = g_strdup(src[i].value.s);
         } else {
             (*dst)[i].value = src[i].value;
         }
@@ -613,9 +607,7 @@ virTypedParamsDeserialize(virTypedParameterRemotePtr remote_params,
                 remote_param->value.remote_typed_param_value.b;
             break;
         case VIR_TYPED_PARAM_STRING:
-            if (VIR_STRDUP(param->value.s,
-                           remote_param->value.remote_typed_param_value.s) < 0)
-                goto cleanup;
+            param->value.s = g_strdup(remote_param->value.remote_typed_param_value.s);
             break;
         default:
             virReportError(VIR_ERR_RPC, _("unknown parameter type: %d"),
@@ -699,8 +691,7 @@ virTypedParamsSerialize(virTypedParameterPtr params,
 
         /* This will be either freed by virNetServerDispatchCall or call(),
          * depending on the calling side, i.e. server or client */
-        if (VIR_STRDUP(val->field, param->field) < 0)
-            goto cleanup;
+        val->field = g_strdup(param->field);
         val->value.type = param->type;
         switch (param->type) {
         case VIR_TYPED_PARAM_INT:
@@ -722,8 +713,7 @@ virTypedParamsSerialize(virTypedParameterPtr params,
             val->value.remote_typed_param_value.b = param->value.b;
             break;
         case VIR_TYPED_PARAM_STRING:
-            if (VIR_STRDUP(val->value.remote_typed_param_value.s, param->value.s) < 0)
-                goto cleanup;
+            val->value.remote_typed_param_value.s = g_strdup(param->value.s);
             break;
         default:
             virReportError(VIR_ERR_RPC, _("unknown parameter type: %d"),
index af2e828c2856a21c364440532335d9e4326d90ad..3532fa5576ffd50a484780993b9e626bf2e29ba0 100644 (file)
@@ -41,8 +41,8 @@ virURIParamAppend(virURIPtr uri,
     char *pname = NULL;
     char *pvalue = NULL;
 
-    if (VIR_STRDUP(pname, name) < 0 || VIR_STRDUP(pvalue, value) < 0)
-        goto error;
+    pname = g_strdup(name);
+    pvalue = g_strdup(value);
 
     if (VIR_RESIZE_N(uri->params, uri->paramsAlloc, uri->paramsCount, 1) < 0)
         goto error;
@@ -167,10 +167,8 @@ virURIParse(const char *uri)
     if (VIR_ALLOC(ret) < 0)
         goto error;
 
-    if (VIR_STRDUP(ret->scheme, xmluri->scheme) < 0)
-        goto error;
-    if (VIR_STRDUP(ret->server, xmluri->server) < 0)
-        goto error;
+    ret->scheme = g_strdup(xmluri->scheme);
+    ret->server = g_strdup(xmluri->server);
     /* xmluri->port value is not defined if server was
      * not given. Modern versions libxml2 fill port
      * differently to old versions in this case, so
@@ -181,14 +179,10 @@ virURIParse(const char *uri)
         ret->port = 0;
     else
         ret->port = xmluri->port;
-    if (VIR_STRDUP(ret->path, xmluri->path) < 0)
-        goto error;
-    if (VIR_STRDUP(ret->query, xmluri->query_raw) < 0)
-        goto error;
-    if (VIR_STRDUP(ret->fragment, xmluri->fragment) < 0)
-        goto error;
-    if (VIR_STRDUP(ret->user, xmluri->user) < 0)
-        goto error;
+    ret->path = g_strdup(xmluri->path);
+    ret->query = g_strdup(xmluri->query_raw);
+    ret->fragment = g_strdup(xmluri->fragment);
+    ret->user = g_strdup(xmluri->user);
 
     /* Strip square bracket from an IPv6 address.
      * The function modifies the string in-place. Even after such
index 036a7caf799ef963615b34aca7c957b6e9bb3e29..5a9f369ac12f007e2287f154ebc90c73f8f4bd0f 100644 (file)
@@ -379,10 +379,8 @@ virUSBDeviceSetUsedBy(virUSBDevicePtr dev,
 {
     VIR_FREE(dev->used_by_drvname);
     VIR_FREE(dev->used_by_domname);
-    if (VIR_STRDUP(dev->used_by_drvname, drv_name) < 0)
-        return -1;
-    if (VIR_STRDUP(dev->used_by_domname, dom_name) < 0)
-        return -1;
+    dev->used_by_drvname = g_strdup(drv_name);
+    dev->used_by_domname = g_strdup(dom_name);
 
     return 0;
 }
index 63071e2fa681e59f6c9b015ff9d8be7f2ee2bb0e..f2528e257cf717cc8b8ca43b6dc2a1afa55a5deb 100644 (file)
@@ -646,14 +646,14 @@ virGetUserEnt(uid_t uid, char **name, gid_t *group, char **dir, char **shell, bo
         goto cleanup;
     }
 
-    if (name && VIR_STRDUP(*name, pw->pw_name) < 0)
-        goto cleanup;
+    if (name)
+        *name = g_strdup(pw->pw_name);
     if (group)
         *group = pw->pw_gid;
-    if (dir && VIR_STRDUP(*dir, pw->pw_dir) < 0)
-        goto cleanup;
-    if (shell && VIR_STRDUP(*shell, pw->pw_shell) < 0)
-        goto cleanup;
+    if (dir)
+        *dir = g_strdup(pw->pw_dir);
+    if (shell)
+        *shell = g_strdup(pw->pw_shell);
 
     ret = 0;
  cleanup:
@@ -1094,8 +1094,8 @@ virGetWin32SpecialFolder(int csidl, char **path)
     *path = NULL;
 
     if (SHGetSpecialFolderLocation(NULL, csidl, &pidl) == S_OK) {
-        if (SHGetPathFromIDList(pidl, buf) && VIR_STRDUP(*path, buf) < 0)
-            ret = -1;
+        if (SHGetPathFromIDList(pidl, buf))
+            *path = g_strdup(buf);
         CoTaskMemFree(pidl);
     }
     return ret;
@@ -1123,7 +1123,8 @@ virGetWin32DirectoryRoot(char **path)
         strcpy(windowsdir, "C:\\");
     }
 
-    return VIR_STRDUP(*path, windowsdir) < 0 ? -1 : 0;
+    *path = g_strdup(windowsdir);
+    return 0;
 }
 
 
@@ -1159,8 +1160,7 @@ virGetUserDirectoryByUID(uid_t uid G_GNUC_UNUSED)
         /* USERPROFILE is probably the closest equivalent to $HOME? */
         dir = getenv("USERPROFILE");
 
-    if (VIR_STRDUP(ret, dir) < 0)
-        return NULL;
+    ret = g_strdup(dir);
 
     if (!ret &&
         virGetWin32SpecialFolder(CSIDL_PROFILE, &ret) < 0)
@@ -1687,8 +1687,7 @@ virParseOwnershipIds(const char *label, uid_t *uidPtr, gid_t *gidPtr)
     char *owner = NULL;
     char *group = NULL;
 
-    if (VIR_STRDUP(tmp_label, label) < 0)
-        goto cleanup;
+    tmp_label = g_strdup(label);
 
     /* Split label */
     sep = strchr(tmp_label, ':');
index 209c83b6cc7d5c2d5bc853015b1b55d61105ffd2..f4c9bc89e521af9c73cd58ad652cd0322dcc2dd9 100644 (file)
@@ -1260,8 +1260,7 @@ virXMLValidatorInit(const char *schemafile)
     if (VIR_ALLOC(validator) < 0)
         return NULL;
 
-    if (VIR_STRDUP(validator->schemafile, schemafile) < 0)
-        goto error;
+    validator->schemafile = g_strdup(schemafile);
 
     if (!(validator->rngParser =
           xmlRelaxNGNewParserCtxt(validator->schemafile))) {