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(a)redhat.com>
---
src/util/virarptable.c | 6 ++---
src/util/virauth.c | 12 +++------
src/util/virauthconfig.c | 6 ++---
src/util/vircommand.c | 44 ++++++++------------------------
src/util/virconf.c | 30 +++++-----------------
src/util/virdbus.c | 9 +++----
src/util/virdnsmasq.c | 13 +++-------
src/util/virerror.c | 12 +++------
src/util/virfcp.c | 3 +--
src/util/virfdstream.c | 10 +++-----
src/util/virfile.c | 40 ++++++++++-------------------
src/util/virfilecache.c | 6 ++---
src/util/virfirewall.c | 3 +--
src/util/virfirmware.c | 10 +++-----
src/util/virhostdev.c | 3 +--
src/util/virhostmem.c | 3 +--
src/util/viriscsi.c | 6 ++---
src/util/virjson.c | 13 +++-------
src/util/virlease.c | 3 +--
src/util/virlockspace.c | 19 ++++----------
src/util/virlog.c | 11 +++-----
src/util/virmdev.c | 9 +++----
src/util/virnetdevmacvlan.c | 12 +++------
src/util/virnetdevopenvswitch.c | 3 +--
src/util/virnetdevtap.c | 6 ++---
src/util/virnetdevvportprofile.c | 5 +---
src/util/virobject.c | 3 +--
src/util/virpci.c | 26 ++++++-------------
src/util/virportallocator.c | 8 +-----
src/util/virresctrl.c | 6 ++---
src/util/virrotatingfile.c | 9 +++----
src/util/virscsi.c | 5 ++--
src/util/virscsivhost.c | 13 +++-------
src/util/virseclabel.c | 19 ++++++--------
src/util/virsecret.c | 3 +--
src/util/virsocketaddr.c | 6 ++---
src/util/virstring.c | 14 +++++-----
src/util/virsysinfo.c | 6 ++---
src/util/virsystemd.c | 3 +--
src/util/virtypedparam-public.c | 6 ++---
src/util/virtypedparam.c | 22 +++++-----------
src/util/viruri.c | 22 ++++++----------
src/util/virusb.c | 6 ++---
src/util/virutil.c | 25 +++++++++---------
src/util/virxml.c | 3 +--
45 files changed, 162 insertions(+), 340 deletions(-)
diff --git a/src/util/virarptable.c b/src/util/virarptable.c
index cc676a0200..265f60d645 100644
--- a/src/util/virarptable.c
+++ b/src/util/virarptable.c
@@ -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++;
}
diff --git a/src/util/virauth.c b/src/util/virauth.c
index 979cb5773e..ddb46cc498 100644
--- a/src/util/virauth.c
+++ b/src/util/virauth.c
@@ -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;
}
diff --git a/src/util/virauthconfig.c b/src/util/virauthconfig.c
index 9e55852cd4..6a9001f2d8 100644
--- a/src/util/virauthconfig.c
+++ b/src/util/virauthconfig.c
@@ -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;
diff --git a/src/util/vircommand.c b/src/util/vircommand.c
index 93b3dd218f..223a2a824e 100644
--- a/src/util/vircommand.c
+++ b/src/util/vircommand.c
@@ -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);
}
diff --git a/src/util/virconf.c b/src/util/virconf.c
index 6f7bf3be8e..3b678015f5 100644
--- a/src/util/virconf.c
+++ b/src/util/virconf.c
@@ -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;
diff --git a/src/util/virdbus.c b/src/util/virdbus.c
index f54c917c03..89c9cb3e24 100644
--- a/src/util/virdbus.c
+++ b/src/util/virdbus.c
@@ -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,
diff --git a/src/util/virdnsmasq.c b/src/util/virdnsmasq.c
index 9aeb7b120d..f22250a07e 100644
--- a/src/util/virdnsmasq.c
+++ b/src/util/virdnsmasq.c
@@ -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:
diff --git a/src/util/virerror.c b/src/util/virerror.c
index 512b2bc7fe..f0ef7e337c 100644
--- a/src/util/virerror.c
+++ b/src/util/virerror.c
@@ -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;
/*
diff --git a/src/util/virfcp.c b/src/util/virfcp.c
index 2315b517bd..80773c7c5d 100644
--- a/src/util/virfcp.c
+++ b/src/util/virfcp.c
@@ -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;
}
diff --git a/src/util/virfdstream.c b/src/util/virfdstream.c
index 693f1619b3..719185d992 100644
--- a/src/util/virfdstream.c
+++ b/src/util/virfdstream.c
@@ -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;
}
diff --git a/src/util/virfile.c b/src/util/virfile.c
index 6a26d4838c..c4d544be73 100644
--- a/src/util/virfile.c
+++ b/src/util/virfile.c
@@ -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;
diff --git a/src/util/virfilecache.c b/src/util/virfilecache.c
index 3a99dc210b..8ab37bae4a 100644
--- a/src/util/virfilecache.c
+++ b/src/util/virfilecache.c
@@ -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;
diff --git a/src/util/virfirewall.c b/src/util/virfirewall.c
index c2e88ec382..fc2c7248cb 100644
--- a/src/util/virfirewall.c
+++ b/src/util/virfirewall.c
@@ -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
diff --git a/src/util/virfirmware.c b/src/util/virfirmware.c
index b4747bd346..9a0610c647 100644
--- a/src/util/virfirmware.c
+++ b/src/util/virfirmware.c
@@ -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]);
}
}
diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c
index 6b29bb1a73..6633b48805 100644
--- a/src/util/virhostdev.c
+++ b/src/util/virhostdev.c
@@ -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,
diff --git a/src/util/virhostmem.c b/src/util/virhostmem.c
index 938e2fa6b3..c1dfc1225c 100644
--- a/src/util/virhostmem.c
+++ b/src/util/virhostmem.c
@@ -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;
diff --git a/src/util/viriscsi.c b/src/util/viriscsi.c
index 1b143ec61f..ba90c41763 100644
--- a/src/util/viriscsi.c
+++ b/src/util/viriscsi.c
@@ -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;
diff --git a/src/util/virjson.c b/src/util/virjson.c
index d3e6c9e41d..eb6207f13f 100644
--- a/src/util/virjson.c
+++ b/src/util/virjson.c
@@ -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,
diff --git a/src/util/virlease.c b/src/util/virlease.c
index 3d851eb808..e0f81539be 100644
--- a/src/util/virlease.c
+++ b/src/util/virlease.c
@@ -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) */
diff --git a/src/util/virlockspace.c b/src/util/virlockspace.c
index d383746183..b0f73c2a8a 100644
--- a/src/util/virlockspace.c
+++ b/src/util/virlockspace.c
@@ -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"));
diff --git a/src/util/virlog.c b/src/util/virlog.c
index 2ce094f6aa..27843363e7 100644
--- a/src/util/virlog.c
+++ b/src/util/virlog.c
@@ -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);
diff --git a/src/util/virmdev.c b/src/util/virmdev.c
index 7e70ceb658..9f8cb95423 100644
--- a/src/util/virmdev.c
+++ b/src/util/virmdev.c
@@ -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);
diff --git a/src/util/virnetdevmacvlan.c b/src/util/virnetdevmacvlan.c
index 4c388b6c55..2ccd83d1bb 100644
--- a/src/util/virnetdevmacvlan.c
+++ b/src/util/virnetdevmacvlan.c
@@ -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 ||
diff --git a/src/util/virnetdevopenvswitch.c b/src/util/virnetdevopenvswitch.c
index 6e13c0f684..1d2bbf9dd7 100644
--- a/src/util/virnetdevopenvswitch.c
+++ b/src/util/virnetdevopenvswitch.c
@@ -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:
diff --git a/src/util/virnetdevtap.c b/src/util/virnetdevtap.c
index 8ca4626a90..fe4f55f8fc 100644
--- a/src/util/virnetdevtap.c
+++ b/src/util/virnetdevtap.c
@@ -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) &&
diff --git a/src/util/virnetdevvportprofile.c b/src/util/virnetdevvportprofile.c
index b001aea3ec..6442c2a2cf 100644
--- a/src/util/virnetdevvportprofile.c
+++ b/src/util/virnetdevvportprofile.c
@@ -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);
diff --git a/src/util/virobject.c b/src/util/virobject.c
index c5363308d8..812b013e72 100644
--- a/src/util/virobject.c
+++ b/src/util/virobject.c
@@ -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;
diff --git a/src/util/virpci.c b/src/util/virpci.c
index 59a93a5e81..f9e39e79d8 100644
--- a/src/util/virpci.c
+++ b/src/util/virpci.c
@@ -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;
diff --git a/src/util/virportallocator.c b/src/util/virportallocator.c
index 1ffd446f40..494bf9107a 100644
--- a/src/util/virportallocator.c
+++ b/src/util/virportallocator.c
@@ -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
diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c
index e52408ed06..29ea52a16f 100644
--- a/src/util/virresctrl.c
+++ b/src/util/virresctrl.c
@@ -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;
}
diff --git a/src/util/virrotatingfile.c b/src/util/virrotatingfile.c
index 1171d3b153..82a677b743 100644
--- a/src/util/virrotatingfile.c
+++ b/src/util/virrotatingfile.c
@@ -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;
diff --git a/src/util/virscsi.c b/src/util/virscsi.c
index af8692eb5b..705571f8ec 100644
--- a/src/util/virscsi.c
+++ b/src/util/virscsi.c
@@ -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;
diff --git a/src/util/virscsivhost.c b/src/util/virscsivhost.c
index 0bcd8902a4..5f523636be 100644
--- a/src/util/virscsivhost.c
+++ b/src/util/virscsivhost.c
@@ -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)
diff --git a/src/util/virseclabel.c b/src/util/virseclabel.c
index 02a834223d..a2b5ebf6b7 100644
--- a/src/util/virseclabel.c
+++ b/src/util/virseclabel.c
@@ -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;
}
diff --git a/src/util/virsecret.c b/src/util/virsecret.c
index 7844a76a56..174ce544c0 100644
--- a/src/util/virsecret.c
+++ b/src/util/virsecret.c
@@ -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;
}
diff --git a/src/util/virsocketaddr.c b/src/util/virsocketaddr.c
index 91e2a8d558..efe942b44c 100644
--- a/src/util/virsocketaddr.c
+++ b/src/util/virsocketaddr.c
@@ -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;
diff --git a/src/util/virstring.c b/src/util/virstring.c
index fcae16c8fe..1494eab132 100644
--- a/src/util/virstring.c
+++ b/src/util/virstring.c
@@ -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;
diff --git a/src/util/virsysinfo.c b/src/util/virsysinfo.c
index af26e0bab9..0a622dbbf9 100644
--- a/src/util/virsysinfo.c
+++ b/src/util/virsysinfo.c
@@ -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,
'=', ',') ||
diff --git a/src/util/virsystemd.c b/src/util/virsystemd.c
index c2e4c3df51..2ff0341b11 100644
--- a/src/util/virsystemd.c
+++ b/src/util/virsystemd.c
@@ -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("");
}
/*
diff --git a/src/util/virtypedparam-public.c b/src/util/virtypedparam-public.c
index eaa9f433e7..0ddb618dbf 100644
--- a/src/util/virtypedparam-public.c
+++ b/src/util/virtypedparam-public.c
@@ -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) {
diff --git a/src/util/virtypedparam.c b/src/util/virtypedparam.c
index db440611dc..f50d926860 100644
--- a/src/util/virtypedparam.c
+++ b/src/util/virtypedparam.c
@@ -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"),
diff --git a/src/util/viruri.c b/src/util/viruri.c
index af2e828c28..3532fa5576 100644
--- a/src/util/viruri.c
+++ b/src/util/viruri.c
@@ -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
diff --git a/src/util/virusb.c b/src/util/virusb.c
index 036a7caf79..5a9f369ac1 100644
--- a/src/util/virusb.c
+++ b/src/util/virusb.c
@@ -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;
}
diff --git a/src/util/virutil.c b/src/util/virutil.c
index 63071e2fa6..f2528e257c 100644
--- a/src/util/virutil.c
+++ b/src/util/virutil.c
@@ -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, ':');
diff --git a/src/util/virxml.c b/src/util/virxml.c
index 209c83b6cc..f4c9bc89e5 100644
--- a/src/util/virxml.c
+++ b/src/util/virxml.c
@@ -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))) {
--
2.21.0