util: use g_strdup instead of VIR_STRDUP

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>
This commit is contained in:
Ján Tomko 2019-10-20 13:49:46 +02:00
parent 8212e5e4ab
commit 18f377178a
45 changed files with 162 additions and 340 deletions

View File

@ -127,8 +127,7 @@ virArpTableGet(void)
virAddr.data.inet4.sin_addr = *(struct in_addr *)addr; virAddr.data.inet4.sin_addr = *(struct in_addr *)addr;
ipstr = virSocketAddrFormat(&virAddr); ipstr = virSocketAddrFormat(&virAddr);
if (VIR_STRDUP(table->t[num].ipaddr, ipstr) < 0) table->t[num].ipaddr = g_strdup(ipstr);
goto cleanup;
} }
if (tb[NDA_LLADDR]) { if (tb[NDA_LLADDR]) {
@ -140,8 +139,7 @@ virArpTableGet(void)
virMacAddrFormat(&macaddr, ifmac); virMacAddrFormat(&macaddr, ifmac);
if (VIR_STRDUP(table->t[num].mac, ifmac) < 0) table->t[num].mac = g_strdup(ifmac);
goto cleanup;
num++; num++;
} }

View File

@ -51,8 +51,7 @@ virAuthGetConfigFilePathURI(virURIPtr uri,
if (authenv) { if (authenv) {
VIR_DEBUG("Using path from env '%s'", authenv); VIR_DEBUG("Using path from env '%s'", authenv);
if (VIR_STRDUP(*path, authenv) < 0) *path = g_strdup(authenv);
return -1;
return 0; return 0;
} }
@ -61,8 +60,7 @@ virAuthGetConfigFilePathURI(virURIPtr uri,
if (STREQ_NULLABLE(uri->params[i].name, "authfile") && if (STREQ_NULLABLE(uri->params[i].name, "authfile") &&
uri->params[i].value) { uri->params[i].value) {
VIR_DEBUG("Using path from URI '%s'", uri->params[i].value); VIR_DEBUG("Using path from URI '%s'", uri->params[i].value);
if (VIR_STRDUP(*path, uri->params[i].value) < 0) *path = g_strdup(uri->params[i].value);
return -1;
return 0; return 0;
} }
} }
@ -80,8 +78,7 @@ virAuthGetConfigFilePathURI(virURIPtr uri,
VIR_FREE(*path); VIR_FREE(*path);
if (VIR_STRDUP(*path, SYSCONFDIR "/libvirt/auth.conf") < 0) *path = g_strdup(SYSCONFDIR "/libvirt/auth.conf");
return -1;
VIR_DEBUG("Checking for readability of '%s'", *path); VIR_DEBUG("Checking for readability of '%s'", *path);
if (access(*path, R_OK) == 0) if (access(*path, R_OK) == 0)
@ -129,8 +126,7 @@ virAuthGetCredential(const char *servicename,
&tmp) < 0) &tmp) < 0)
return -1; return -1;
if (VIR_STRDUP(*value, tmp) < 0) *value = g_strdup(tmp);
return -1;
return 0; return 0;
} }

View File

@ -44,8 +44,7 @@ virAuthConfigPtr virAuthConfigNew(const char *path)
if (VIR_ALLOC(auth) < 0) if (VIR_ALLOC(auth) < 0)
goto error; goto error;
if (VIR_STRDUP(auth->path, path) < 0) auth->path = g_strdup(path);
goto error;
if (!(auth->keyfile = virKeyFileNew())) if (!(auth->keyfile = virKeyFileNew()))
goto error; goto error;
@ -70,8 +69,7 @@ virAuthConfigPtr virAuthConfigNewData(const char *path,
if (VIR_ALLOC(auth) < 0) if (VIR_ALLOC(auth) < 0)
goto error; goto error;
if (VIR_STRDUP(auth->path, path) < 0) auth->path = g_strdup(path);
goto error;
if (!(auth->keyfile = virKeyFileNew())) if (!(auth->keyfile = virKeyFileNew()))
goto error; goto error;

View File

@ -1061,8 +1061,7 @@ virCommandSetPidFile(virCommandPtr cmd, const char *pidfile)
return; return;
VIR_FREE(cmd->pidfile); VIR_FREE(cmd->pidfile);
if (VIR_STRDUP_QUIET(cmd->pidfile, pidfile) < 0) cmd->pidfile = g_strdup(pidfile);
cmd->has_error = ENOMEM;
} }
@ -1194,8 +1193,7 @@ virCommandSetSELinuxLabel(virCommandPtr cmd,
#if defined(WITH_SECDRIVER_SELINUX) #if defined(WITH_SECDRIVER_SELINUX)
VIR_FREE(cmd->seLinuxLabel); VIR_FREE(cmd->seLinuxLabel);
if (VIR_STRDUP_QUIET(cmd->seLinuxLabel, label) < 0) cmd->seLinuxLabel = g_strdup(label);
cmd->has_error = ENOMEM;
#endif #endif
return; return;
} }
@ -1219,8 +1217,7 @@ virCommandSetAppArmorProfile(virCommandPtr cmd,
#if defined(WITH_SECDRIVER_APPARMOR) #if defined(WITH_SECDRIVER_APPARMOR)
VIR_FREE(cmd->appArmorProfile); VIR_FREE(cmd->appArmorProfile);
if (VIR_STRDUP_QUIET(cmd->appArmorProfile, profile) < 0) cmd->appArmorProfile = g_strdup(profile);
cmd->has_error = ENOMEM;
#endif #endif
return; return;
} }
@ -1369,10 +1366,7 @@ virCommandAddEnvString(virCommandPtr cmd, const char *str)
if (!cmd || cmd->has_error) if (!cmd || cmd->has_error)
return; return;
if (VIR_STRDUP_QUIET(env, str) < 0) { env = g_strdup(str);
cmd->has_error = ENOMEM;
return;
}
virCommandAddEnv(cmd, env); virCommandAddEnv(cmd, env);
} }
@ -1501,10 +1495,7 @@ virCommandAddArg(virCommandPtr cmd, const char *val)
return; return;
} }
if (VIR_STRDUP_QUIET(arg, val) < 0) { arg = g_strdup(val);
cmd->has_error = ENOMEM;
return;
}
/* Arg plus trailing NULL. */ /* Arg plus trailing NULL. */
if (VIR_RESIZE_N(cmd->args, cmd->maxargs, cmd->nargs, 1 + 1) < 0) { 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); cmd->args[cmd->nargs] = virBufferContentAndReset(buf);
if (!cmd->args[cmd->nargs]) { if (!cmd->args[cmd->nargs])
if (VIR_STRDUP_QUIET(cmd->args[cmd->nargs], "") < 0) { cmd->args[cmd->nargs] = g_strdup("");
cmd->has_error = ENOMEM;
return;
}
}
cmd->nargs++; cmd->nargs++;
} }
@ -1638,10 +1625,7 @@ virCommandAddArgSet(virCommandPtr cmd, const char *const*vals)
while (vals[narg] != NULL) { while (vals[narg] != NULL) {
char *arg; char *arg;
if (VIR_STRDUP_QUIET(arg, vals[narg++]) < 0) { arg = g_strdup(vals[narg++]);
cmd->has_error = ENOMEM;
return;
}
cmd->args[cmd->nargs++] = arg; cmd->args[cmd->nargs++] = arg;
} }
} }
@ -1678,11 +1662,7 @@ virCommandAddArgList(virCommandPtr cmd, ...)
char *arg = va_arg(list, char *); char *arg = va_arg(list, char *);
if (!arg) if (!arg)
break; break;
if (VIR_STRDUP_QUIET(arg, arg) < 0) { arg = g_strdup(arg);
cmd->has_error = ENOMEM;
va_end(list);
return;
}
cmd->args[cmd->nargs++] = arg; cmd->args[cmd->nargs++] = arg;
} }
va_end(list); va_end(list);
@ -1707,8 +1687,7 @@ virCommandSetWorkingDirectory(virCommandPtr cmd, const char *pwd)
cmd->has_error = -1; cmd->has_error = -1;
VIR_DEBUG("cannot set directory twice"); VIR_DEBUG("cannot set directory twice");
} else { } else {
if (VIR_STRDUP_QUIET(cmd->pwd, pwd) < 0) cmd->pwd = g_strdup(pwd);
cmd->has_error = ENOMEM;
} }
} }
@ -1869,8 +1848,7 @@ virCommandSetInputBuffer(virCommandPtr cmd, const char *inbuf)
return; return;
} }
if (VIR_STRDUP_QUIET(cmd->inbuf, inbuf) < 0) cmd->inbuf = g_strdup(inbuf);
cmd->has_error = ENOMEM;
} }

View File

@ -187,10 +187,7 @@ virConfCreate(const char *filename, unsigned int flags)
if (!ret) if (!ret)
return NULL; return NULL;
if (VIR_STRDUP(ret->filename, filename) < 0) { ret->filename = g_strdup(filename);
VIR_FREE(ret);
return NULL;
}
ret->flags = flags; ret->flags = flags;
return ret; return ret;
@ -905,8 +902,7 @@ int virConfGetValueString(virConfPtr conf,
} }
VIR_FREE(*value); VIR_FREE(*value);
if (VIR_STRDUP(*value, cval->str) < 0) *value = g_strdup(cval->str);
return -1;
return 1; return 1;
} }
@ -964,24 +960,16 @@ int virConfGetValueStringList(virConfPtr conf,
if (VIR_ALLOC_N(*values, len + 1) < 0) if (VIR_ALLOC_N(*values, len + 1) < 0)
return -1; return -1;
for (len = 0, eval = cval->list; eval; len++, eval = eval->next) { for (len = 0, eval = cval->list; eval; len++, eval = eval->next)
if (VIR_STRDUP((*values)[len], eval->str) < 0) { (*values)[len] = g_strdup(eval->str);
virStringListFree(*values);
*values = NULL;
return -1;
}
}
break; break;
case VIR_CONF_STRING: case VIR_CONF_STRING:
if (compatString) { if (compatString) {
if (VIR_ALLOC_N(*values, cval->str ? 2 : 1) < 0) if (VIR_ALLOC_N(*values, cval->str ? 2 : 1) < 0)
return -1; return -1;
if (cval->str && if (cval->str)
VIR_STRDUP((*values)[0], cval->str) < 0) { (*values)[0] = g_strdup(cval->str);
VIR_FREE(*values);
return -1;
}
break; break;
} }
G_GNUC_FALLTHROUGH; G_GNUC_FALLTHROUGH;
@ -1383,11 +1371,7 @@ virConfSetValue(virConfPtr conf,
return -1; return -1;
} }
cur->comment = NULL; cur->comment = NULL;
if (VIR_STRDUP(cur->name, setting) < 0) { cur->name = g_strdup(setting);
virConfFreeValue(value);
VIR_FREE(cur);
return -1;
}
cur->value = value; cur->value = value;
if (prev) { if (prev) {
cur->next = prev->next; cur->next = prev->next;

View File

@ -1010,8 +1010,7 @@ virDBusMessageIterDecode(DBusMessageIter *rootiter,
} }
char *s; char *s;
dbus_message_iter_get_basic(iter, &s); dbus_message_iter_get_basic(iter, &s);
if (VIR_STRDUP(*x, s) < 0) *x = g_strdup(s);
goto cleanup;
VIR_DEBUG("Read basic type 'char *' varg 'char **'" VIR_DEBUG("Read basic type 'char *' varg 'char **'"
"' val '%s'", *x); "' val '%s'", *x);
} while (0); } while (0);
@ -1573,10 +1572,8 @@ virDBusCall(DBusConnection *conn,
error->level = VIR_ERR_ERROR; error->level = VIR_ERR_ERROR;
error->code = VIR_ERR_DBUS_SERVICE; error->code = VIR_ERR_DBUS_SERVICE;
error->domain = VIR_FROM_DBUS; error->domain = VIR_FROM_DBUS;
if (VIR_STRDUP(error->message, localerror.message) < 0) error->message = g_strdup(localerror.message);
goto cleanup; error->str1 = g_strdup(localerror.name);
if (VIR_STRDUP(error->str1, localerror.name) < 0)
goto cleanup;
ret = 0; ret = 0;
} else { } else {
virReportError(VIR_ERR_DBUS_SERVICE, _("%s: %s"), member, virReportError(VIR_ERR_DBUS_SERVICE, _("%s: %s"), member,

View File

@ -112,8 +112,7 @@ addnhostsAdd(dnsmasqAddnHostsfile *addnhostsfile,
if (VIR_ALLOC(addnhostsfile->hosts[idx].hostnames) < 0) if (VIR_ALLOC(addnhostsfile->hosts[idx].hostnames) < 0)
goto error; goto error;
if (VIR_STRDUP(addnhostsfile->hosts[idx].ip, ipstr) < 0) addnhostsfile->hosts[idx].ip = g_strdup(ipstr);
goto error;
addnhostsfile->hosts[idx].nhostnames = 0; addnhostsfile->hosts[idx].nhostnames = 0;
addnhostsfile->nhosts++; addnhostsfile->nhosts++;
@ -122,9 +121,7 @@ addnhostsAdd(dnsmasqAddnHostsfile *addnhostsfile,
if (VIR_REALLOC_N(addnhostsfile->hosts[idx].hostnames, addnhostsfile->hosts[idx].nhostnames + 1) < 0) if (VIR_REALLOC_N(addnhostsfile->hosts[idx].hostnames, addnhostsfile->hosts[idx].nhostnames + 1) < 0)
goto error; goto error;
if (VIR_STRDUP(addnhostsfile->hosts[idx].hostnames[addnhostsfile->hosts[idx].nhostnames], addnhostsfile->hosts[idx].hostnames[addnhostsfile->hosts[idx].nhostnames] = g_strdup(name);
name) < 0)
goto error;
VIR_FREE(ipstr); VIR_FREE(ipstr);
@ -467,8 +464,7 @@ dnsmasqContextNew(const char *network_name,
if (VIR_ALLOC(ctx) < 0) if (VIR_ALLOC(ctx) < 0)
return NULL; return NULL;
if (VIR_STRDUP(ctx->config_dir, config_dir) < 0) ctx->config_dir = g_strdup(config_dir);
goto error;
if (!(ctx->hostsfile = hostsfileNew(network_name, config_dir))) if (!(ctx->hostsfile = hostsfileNew(network_name, config_dir)))
goto error; goto error;
@ -786,8 +782,7 @@ dnsmasqCapsNewEmpty(const char *binaryPath)
return NULL; return NULL;
if (!(caps->flags = virBitmapNew(DNSMASQ_CAPS_LAST))) if (!(caps->flags = virBitmapNew(DNSMASQ_CAPS_LAST)))
goto error; goto error;
if (VIR_STRDUP(caps->binaryPath, binaryPath ? binaryPath : DNSMASQ) < 0) caps->binaryPath = g_strdup(binaryPath ? binaryPath : DNSMASQ);
goto error;
return caps; return caps;
error: error:

View File

@ -207,14 +207,10 @@ virCopyError(virErrorPtr from,
to->code = from->code; to->code = from->code;
to->domain = from->domain; to->domain = from->domain;
to->level = from->level; to->level = from->level;
if (VIR_STRDUP_QUIET(to->message, from->message) < 0) to->message = g_strdup(from->message);
ret = -1; to->str1 = g_strdup(from->str1);
if (VIR_STRDUP_QUIET(to->str1, from->str1) < 0) to->str2 = g_strdup(from->str2);
ret = -1; to->str3 = g_strdup(from->str3);
if (VIR_STRDUP_QUIET(to->str2, from->str2) < 0)
ret = -1;
if (VIR_STRDUP_QUIET(to->str3, from->str3) < 0)
ret = -1;
to->int1 = from->int1; to->int1 = from->int1;
to->int2 = from->int2; to->int2 = from->int2;
/* /*

View File

@ -62,8 +62,7 @@ virFCReadRportValue(const char *rport,
if ((p = strchr(buf, '\n'))) if ((p = strchr(buf, '\n')))
*p = '\0'; *p = '\0';
if (VIR_STRDUP(*result, buf) < 0) *result = g_strdup(buf);
return -1;
return 0; return 0;
} }

View File

@ -1302,17 +1302,15 @@ virFDStreamOpenFileInternal(virStreamPtr st,
if ((oflags & O_ACCMODE) == O_RDONLY) { if ((oflags & O_ACCMODE) == O_RDONLY) {
threadData->fdin = fd; threadData->fdin = fd;
threadData->fdout = pipefds[1]; threadData->fdout = pipefds[1];
if (VIR_STRDUP(threadData->fdinname, path) < 0 || threadData->fdinname = g_strdup(path);
VIR_STRDUP(threadData->fdoutname, "pipe") < 0) threadData->fdoutname = g_strdup("pipe");
goto error;
tmpfd = pipefds[0]; tmpfd = pipefds[0];
threadData->doRead = true; threadData->doRead = true;
} else { } else {
threadData->fdin = pipefds[0]; threadData->fdin = pipefds[0];
threadData->fdout = fd; threadData->fdout = fd;
if (VIR_STRDUP(threadData->fdinname, "pipe") < 0 || threadData->fdinname = g_strdup("pipe");
VIR_STRDUP(threadData->fdoutname, path) < 0) threadData->fdoutname = g_strdup(path);
goto error;
tmpfd = pipefds[1]; tmpfd = pipefds[1];
threadData->doRead = false; threadData->doRead = false;
} }

View File

@ -1578,8 +1578,10 @@ virFileResolveLinkHelper(const char *linkpath,
if (lstat(linkpath, &st) < 0) if (lstat(linkpath, &st) < 0)
return -1; return -1;
if (!S_ISLNK(st.st_mode)) if (!S_ISLNK(st.st_mode)) {
return VIR_STRDUP_QUIET(*resultpath, linkpath) < 0 ? -1 : 0; *resultpath = g_strdup(linkpath);
return 0;
}
} }
*resultpath = virFileCanonicalizePath(linkpath); *resultpath = virFileCanonicalizePath(linkpath);
@ -1684,9 +1686,7 @@ virFindFileInPath(const char *file)
origpath = getenv("PATH"); origpath = getenv("PATH");
if (!origpath) if (!origpath)
origpath = "/bin:/usr/bin"; origpath = "/bin:/usr/bin";
path = g_strdup(origpath);
if (VIR_STRDUP_QUIET(path, origpath) <= 0)
return NULL;
/* for each path segment, append the file to search for and test for /* for each path segment, append the file to search for and test for
* it. return it if found. * it. return it if found.
@ -2023,8 +2023,7 @@ virFileGetMountSubtreeImpl(const char *mtabpath,
if (VIR_EXPAND_N(mounts, nmounts, nmounts ? 1 : 2) < 0) if (VIR_EXPAND_N(mounts, nmounts, nmounts ? 1 : 2) < 0)
goto cleanup; goto cleanup;
if (VIR_STRDUP(mounts[nmounts - 2], mntent.mnt_dir) < 0) mounts[nmounts - 2] = g_strdup(mntent.mnt_dir);
goto cleanup;
} }
if (mounts) if (mounts)
@ -3070,10 +3069,7 @@ virFileMakePathWithMode(const char *path,
{ {
g_autofree char *tmp = NULL; g_autofree char *tmp = NULL;
if (VIR_STRDUP(tmp, path) < 0) { tmp = g_strdup(path);
errno = ENOMEM;
return -1;
}
return virFileMakePathHelper(tmp, mode); return virFileMakePathHelper(tmp, mode);
} }
@ -3087,10 +3083,7 @@ virFileMakeParentPath(const char *path)
VIR_DEBUG("path=%s", path); VIR_DEBUG("path=%s", path);
if (VIR_STRDUP(tmp, path) < 0) { tmp = g_strdup(path);
errno = ENOMEM;
return -1;
}
if ((p = strrchr(tmp, '/')) == NULL) { if ((p = strrchr(tmp, '/')) == NULL) {
errno = EINVAL; errno = EINVAL;
@ -3293,8 +3286,7 @@ int
virFileAbsPath(const char *path, char **abspath) virFileAbsPath(const char *path, char **abspath)
{ {
if (path[0] == '/') { if (path[0] == '/') {
if (VIR_STRDUP(*abspath, path) < 0) *abspath = g_strdup(path);
return -1;
} else { } else {
g_autofree char *buf = getcwd(NULL, 0); g_autofree char *buf = getcwd(NULL, 0);
@ -3317,8 +3309,7 @@ virFileSanitizePath(const char *path)
char *cleanpath; char *cleanpath;
int idx = 0; int idx = 0;
if (VIR_STRDUP(cleanpath, path) < 0) cleanpath = g_strdup(path);
return NULL;
/* don't sanitize URIs - rfc3986 states that two slashes may lead to a /* don't sanitize URIs - rfc3986 states that two slashes may lead to a
* different resource, thus removing them would possibly change the path */ * different resource, thus removing them would possibly change the path */
@ -3504,9 +3495,8 @@ virFileIsSharedFixFUSE(const char *path,
maxMatching = len; maxMatching = len;
VIR_FREE(mntType); VIR_FREE(mntType);
VIR_FREE(mntDir); VIR_FREE(mntDir);
if (VIR_STRDUP(mntDir, mb.mnt_dir) < 0 || mntDir = g_strdup(mb.mnt_dir);
VIR_STRDUP(mntType, mb.mnt_type) < 0) mntType = g_strdup(mb.mnt_type);
goto cleanup;
} }
} }
@ -3540,8 +3530,7 @@ virFileIsSharedFSType(const char *path,
int statfs_ret; int statfs_ret;
long long f_type = 0; long long f_type = 0;
if (VIR_STRDUP(dirpath, path) < 0) dirpath = g_strdup(path);
return -1;
statfs_ret = statfs(dirpath, &sb); statfs_ret = statfs(dirpath, &sb);
@ -3712,8 +3701,7 @@ virFileFindHugeTLBFS(virHugeTLBFSPtr *ret_fs,
tmp = &fs[nfs - 1]; tmp = &fs[nfs - 1];
if (VIR_STRDUP(tmp->mnt_dir, mb.mnt_dir) < 0) tmp->mnt_dir = g_strdup(mb.mnt_dir);
goto cleanup;
if (virFileGetHugepageSize(tmp->mnt_dir, &tmp->size) < 0) if (virFileGetHugepageSize(tmp->mnt_dir, &tmp->size) < 0)
goto cleanup; goto cleanup;

View File

@ -245,11 +245,9 @@ virFileCacheNew(const char *dir,
if (!(cache->table = virHashCreate(10, virObjectFreeHashData))) if (!(cache->table = virHashCreate(10, virObjectFreeHashData)))
goto cleanup; goto cleanup;
if (VIR_STRDUP(cache->dir, dir) < 0) cache->dir = g_strdup(dir);
goto cleanup;
if (VIR_STRDUP(cache->suffix, suffix) < 0) cache->suffix = g_strdup(suffix);
goto cleanup;
cache->handlers = *handlers; cache->handlers = *handlers;

View File

@ -323,8 +323,7 @@ void virFirewallFree(virFirewallPtr firewall)
rule->argsLen, 1) < 0) \ rule->argsLen, 1) < 0) \
goto no_memory; \ goto no_memory; \
\ \
if (VIR_STRDUP(rule->args[rule->argsLen++], str) < 0) \ rule->args[rule->argsLen++] = g_strdup(str); \
goto no_memory; \
} while (0) } while (0)
static virFirewallRulePtr static virFirewallRulePtr

View File

@ -79,9 +79,8 @@ virFirmwareParse(const char *str, virFirmwarePtr firmware)
goto cleanup; goto cleanup;
} }
if (VIR_STRDUP(firmware->name, token[0]) < 0 || firmware->name = g_strdup(token[0]);
VIR_STRDUP(firmware->nvram, token[1]) < 0) firmware->nvram = g_strdup(token[1]);
goto cleanup;
ret = 0; ret = 0;
cleanup: cleanup:
@ -122,9 +121,8 @@ virFirmwareParseList(const char *list,
if (VIR_ALLOC(fws[j]) < 0) if (VIR_ALLOC(fws[j]) < 0)
goto cleanup; goto cleanup;
if (VIR_STRDUP(fws[j]->name, token[2 * j]) < 0 || fws[j]->name = g_strdup(token[2 * j]);
VIR_STRDUP(fws[j]->nvram, token[2 * j + 1]) < 0) fws[j]->nvram = g_strdup(token[2 * j + 1]);
goto cleanup;
} }
} }

View File

@ -169,8 +169,7 @@ virHostdevManagerNew(void)
return NULL; return NULL;
if (privileged) { if (privileged) {
if (VIR_STRDUP(hostdevMgr->stateDir, HOSTDEV_STATE_DIR) < 0) hostdevMgr->stateDir = g_strdup(HOSTDEV_STATE_DIR);
return NULL;
if (virFileMakePath(hostdevMgr->stateDir) < 0) { if (virFileMakePath(hostdevMgr->stateDir) < 0) {
virReportError(VIR_ERR_OPERATION_FAILED, virReportError(VIR_ERR_OPERATION_FAILED,

View File

@ -268,8 +268,7 @@ virHostMemGetStats(int cellNum G_GNUC_UNUSED,
cellNum = VIR_NODE_MEMORY_STATS_ALL_CELLS; cellNum = VIR_NODE_MEMORY_STATS_ALL_CELLS;
if (cellNum == VIR_NODE_MEMORY_STATS_ALL_CELLS) { if (cellNum == VIR_NODE_MEMORY_STATS_ALL_CELLS) {
if (VIR_STRDUP(meminfo_path, MEMINFO_PATH) < 0) meminfo_path = g_strdup(MEMINFO_PATH);
return -1;
} else { } else {
if ((max_node = virNumaGetMaxNode()) < 0) if ((max_node = virNumaGetMaxNode()) < 0)
return -1; return -1;

View File

@ -176,8 +176,7 @@ virStorageBackendIQNFound(const char *initiatoriqn,
current = next + 1; current = next + 1;
} }
if (VIR_STRDUP(iqn, current) < 0) iqn = g_strdup(current);
goto cleanup;
if (STREQ(iqn, initiatoriqn)) { if (STREQ(iqn, initiatoriqn)) {
*ifacename = g_steal_pointer(&iface); *ifacename = g_steal_pointer(&iface);
@ -373,8 +372,7 @@ virISCSIGetTargets(char **const groups,
struct virISCSITargetList *list = data; struct virISCSITargetList *list = data;
g_autofree char *target = NULL; g_autofree char *target = NULL;
if (VIR_STRDUP(target, groups[1]) < 0) target = g_strdup(groups[1]);
return -1;
if (VIR_APPEND_ELEMENT(list->targets, list->ntargets, target) < 0) if (VIR_APPEND_ELEMENT(list->targets, list->ntargets, target) < 0)
return -1; return -1;

View File

@ -450,10 +450,7 @@ virJSONValueNewString(const char *data)
return NULL; return NULL;
val->type = VIR_JSON_TYPE_STRING; val->type = VIR_JSON_TYPE_STRING;
if (VIR_STRDUP(val->data.string, data) < 0) { val->data.string = g_strdup(data);
VIR_FREE(val);
return NULL;
}
return val; return val;
} }
@ -490,10 +487,7 @@ virJSONValueNewNumber(const char *data)
return NULL; return NULL;
val->type = VIR_JSON_TYPE_NUMBER; val->type = VIR_JSON_TYPE_NUMBER;
if (VIR_STRDUP(val->data.number, data) < 0) { val->data.number = g_strdup(data);
VIR_FREE(val);
return NULL;
}
return val; return val;
} }
@ -626,8 +620,7 @@ virJSONValueObjectInsert(virJSONValuePtr object,
return -1; return -1;
} }
if (VIR_STRDUP(pair.key, key) < 0) pair.key = g_strdup(key);
return -1;
if (prepend) { if (prepend) {
ret = VIR_INSERT_ELEMENT(object->data.object.pairs, 0, ret = VIR_INSERT_ELEMENT(object->data.object.pairs, 0,

View File

@ -221,8 +221,7 @@ virLeaseNew(virJSONValuePtr *lease_ret,
return 0; return 0;
if (exptime_tmp) { if (exptime_tmp) {
if (VIR_STRDUP(exptime, exptime_tmp) < 0) exptime = g_strdup(exptime_tmp);
return -1;
/* Removed extraneous trailing space in DNSMASQ_LEASE_EXPIRES /* Removed extraneous trailing space in DNSMASQ_LEASE_EXPIRES
* (dnsmasq < 2.52) */ * (dnsmasq < 2.52) */

View File

@ -127,8 +127,7 @@ virLockSpaceResourceNew(virLockSpacePtr lockspace,
res->fd = -1; res->fd = -1;
res->flags = flags; res->flags = flags;
if (VIR_STRDUP(res->name, resname) < 0) res->name = g_strdup(resname);
goto error;
if (!(res->path = virLockSpaceGetResourcePath(lockspace, resname))) if (!(res->path = virLockSpaceGetResourcePath(lockspace, resname)))
goto error; goto error;
@ -255,8 +254,7 @@ virLockSpacePtr virLockSpaceNew(const char *directory)
return NULL; return NULL;
} }
if (VIR_STRDUP(lockspace->dir, directory) < 0) lockspace->dir = g_strdup(directory);
goto error;
if (!(lockspace->resources = virHashCreate(VIR_LOCKSPACE_TABLE_SIZE, if (!(lockspace->resources = virHashCreate(VIR_LOCKSPACE_TABLE_SIZE,
virLockSpaceResourceDataFree))) virLockSpaceResourceDataFree)))
@ -313,8 +311,7 @@ virLockSpacePtr virLockSpaceNewPostExecRestart(virJSONValuePtr object)
if (virJSONValueObjectHasKey(object, "directory")) { if (virJSONValueObjectHasKey(object, "directory")) {
const char *dir = virJSONValueObjectGetString(object, "directory"); const char *dir = virJSONValueObjectGetString(object, "directory");
if (VIR_STRDUP(lockspace->dir, dir) < 0) lockspace->dir = g_strdup(dir);
goto error;
} }
if (!(resources = virJSONValueObjectGet(object, "resources"))) { if (!(resources = virJSONValueObjectGet(object, "resources"))) {
@ -347,10 +344,7 @@ virLockSpacePtr virLockSpaceNewPostExecRestart(virJSONValuePtr object)
virLockSpaceResourceFree(res); virLockSpaceResourceFree(res);
goto error; goto error;
} }
if (VIR_STRDUP(res->name, tmp) < 0) { res->name = g_strdup(tmp);
virLockSpaceResourceFree(res);
goto error;
}
if (!(tmp = virJSONValueObjectGetString(child, "path"))) { if (!(tmp = virJSONValueObjectGetString(child, "path"))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@ -358,10 +352,7 @@ virLockSpacePtr virLockSpaceNewPostExecRestart(virJSONValuePtr object)
virLockSpaceResourceFree(res); virLockSpaceResourceFree(res);
goto error; goto error;
} }
if (VIR_STRDUP(res->path, tmp) < 0) { res->path = g_strdup(tmp);
virLockSpaceResourceFree(res);
goto error;
}
if (virJSONValueObjectGetNumberInt(child, "fd", &res->fd) < 0) { if (virJSONValueObjectGetNumberInt(child, "fd", &res->fd) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Missing resource fd in JSON document")); _("Missing resource fd in JSON document"));

View File

@ -840,8 +840,7 @@ virLogNewOutputToSyslog(virLogPriority priority,
* rather than copying @ident, syslog uses caller's reference instead * rather than copying @ident, syslog uses caller's reference instead
*/ */
VIR_FREE(current_ident); VIR_FREE(current_ident);
if (VIR_STRDUP(current_ident, ident) < 0) current_ident = g_strdup(ident);
return NULL;
openlog(current_ident, 0, 0); openlog(current_ident, 0, 0);
} }
@ -1331,8 +1330,7 @@ virLogOutputNew(virLogOutputFunc f,
return NULL; return NULL;
} }
if (VIR_STRDUP(ndup, name) < 0) ndup = g_strdup(name);
return NULL;
} }
if (VIR_ALLOC(ret) < 0) { 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 * holding the lock so it's safe to call openlog and change the message
* tag * tag
*/ */
if (VIR_STRDUP_QUIET(tmp, outputs[id]->name) < 0) { tmp = g_strdup(outputs[id]->name);
virLogUnlock();
return -1;
}
VIR_FREE(current_ident); VIR_FREE(current_ident);
current_ident = tmp; current_ident = tmp;
openlog(current_ident, 0, 0); openlog(current_ident, 0, 0);

View File

@ -271,10 +271,8 @@ virMediatedDeviceSetUsedBy(virMediatedDevicePtr dev,
{ {
VIR_FREE(dev->used_by_drvname); VIR_FREE(dev->used_by_drvname);
VIR_FREE(dev->used_by_domname); VIR_FREE(dev->used_by_domname);
if (VIR_STRDUP(dev->used_by_drvname, drvname) < 0) dev->used_by_drvname = g_strdup(drvname);
return -1; dev->used_by_domname = g_strdup(domname);
if (VIR_STRDUP(dev->used_by_domname, domname) < 0)
return -1;
return 0; return 0;
} }
@ -509,8 +507,7 @@ virMediatedDeviceTypeReadAttrs(const char *sysfspath,
if (VIR_ALLOC(tmp) < 0) if (VIR_ALLOC(tmp) < 0)
return -1; return -1;
if (VIR_STRDUP(tmp->id, last_component(sysfspath)) < 0) tmp->id = g_strdup(last_component(sysfspath));
return -1;
/* @name sysfs attribute is optional, so getting ENOENT is fine */ /* @name sysfs attribute is optional, so getting ENOENT is fine */
MDEV_GET_SYSFS_ATTR("name", &tmp->name, virFileReadValueString, true); MDEV_GET_SYSFS_ATTR("name", &tmp->name, virFileReadValueString, true);

View File

@ -836,14 +836,12 @@ virNetDevMacVLanVPortProfileRegisterCallback(const char *ifname,
if (virtPortProfile && virNetlinkEventServiceIsRunning(NETLINK_ROUTE)) { if (virtPortProfile && virNetlinkEventServiceIsRunning(NETLINK_ROUTE)) {
if (VIR_ALLOC(calld) < 0) if (VIR_ALLOC(calld) < 0)
goto error; goto error;
if (VIR_STRDUP(calld->cr_ifname, ifname) < 0) calld->cr_ifname = g_strdup(ifname);
goto error;
if (VIR_ALLOC(calld->virtPortProfile) < 0) if (VIR_ALLOC(calld->virtPortProfile) < 0)
goto error; goto error;
memcpy(calld->virtPortProfile, virtPortProfile, sizeof(*virtPortProfile)); memcpy(calld->virtPortProfile, virtPortProfile, sizeof(*virtPortProfile));
virMacAddrSet(&calld->macaddress, macaddress); virMacAddrSet(&calld->macaddress, macaddress);
if (VIR_STRDUP(calld->linkdev, linkdev) < 0) calld->linkdev = g_strdup(linkdev);
goto error;
memcpy(calld->vmuuid, vmuuid, sizeof(calld->vmuuid)); memcpy(calld->vmuuid, vmuuid, sizeof(calld->vmuuid));
calld->vmOp = vmOp; calld->vmOp = vmOp;
@ -1044,11 +1042,9 @@ virNetDevMacVLanCreateWithVPortProfile(const char *ifnameRequested,
if (virNetDevMacVLanTapSetup(tapfd, tapfdSize, vnet_hdr) < 0) if (virNetDevMacVLanTapSetup(tapfd, tapfdSize, vnet_hdr) < 0)
goto disassociate_exit; goto disassociate_exit;
if (VIR_STRDUP(*ifnameResult, ifnameCreated) < 0) *ifnameResult = g_strdup(ifnameCreated);
goto disassociate_exit;
} else { } else {
if (VIR_STRDUP(*ifnameResult, ifnameCreated) < 0) *ifnameResult = g_strdup(ifnameCreated);
goto disassociate_exit;
} }
if (vmOp == VIR_NETDEV_VPORT_PROFILE_OP_CREATE || if (vmOp == VIR_NETDEV_VPORT_PROFILE_OP_CREATE ||

View File

@ -529,8 +529,7 @@ virNetDevOpenvswitchGetVhostuserIfname(const char *path,
goto cleanup; goto cleanup;
} }
if (VIR_STRDUP(*ifname, tmpIfname) < 0) *ifname = g_strdup(tmpIfname);
goto cleanup;
ret = 1; ret = 1;
cleanup: cleanup:

View File

@ -73,7 +73,8 @@ virNetDevTapGetName(int tapfd G_GNUC_UNUSED, char **ifname G_GNUC_UNUSED)
return -1; return -1;
} }
return VIR_STRDUP(*ifname, ifr.ifr_name) < 0 ? -1 : 0; *ifname = g_strdup(ifr.ifr_name);
return 0;
#else #else
return -1; return -1;
#endif #endif
@ -282,8 +283,7 @@ int virNetDevTapCreate(char **ifname,
/* In case we are looping more than once, set other /* In case we are looping more than once, set other
* TAPs to have the same name */ * TAPs to have the same name */
VIR_FREE(*ifname); VIR_FREE(*ifname);
if (VIR_STRDUP(*ifname, ifr.ifr_name) < 0) *ifname = g_strdup(ifr.ifr_name);
goto cleanup;
} }
if ((flags & VIR_NETDEV_TAP_CREATE_PERSIST) && if ((flags & VIR_NETDEV_TAP_CREATE_PERSIST) &&

View File

@ -1145,10 +1145,7 @@ virNetDevVPortProfileOp8021Qbh(const char *ifname,
goto cleanup; goto cleanup;
} }
} else { } else {
if (VIR_STRDUP(physfndev, ifname) < 0) { physfndev = g_strdup(ifname);
rc = -1;
goto cleanup;
}
} }
rc = virNetDevGetIndex(physfndev, &ifindex); rc = virNetDevGetIndex(physfndev, &ifindex);

View File

@ -188,8 +188,7 @@ virClassNew(virClassPtr parent,
_("too many object classes defined")); _("too many object classes defined"));
goto error; goto error;
} }
if (VIR_STRDUP(klass->name, name) < 0) klass->name = g_strdup(name);
goto error;
klass->objectSize = objectSize; klass->objectSize = objectSize;
klass->dispose = dispose; klass->dispose = dispose;

View File

@ -265,8 +265,7 @@ virPCIDeviceGetDriverPathAndName(virPCIDevicePtr dev, char **path, char **name)
} }
/* path = "/sys/bus/pci/drivers/${drivername}" */ /* path = "/sys/bus/pci/drivers/${drivername}" */
if (VIR_STRDUP(*name, last_component(*path)) < 0) *name = g_strdup(last_component(*path));
goto cleanup;
/* name = "${drivername}" */ /* name = "${drivername}" */
ret = 0; ret = 0;
@ -1435,17 +1434,11 @@ virPCIDeviceCopy(virPCIDevicePtr dev)
*copy = *dev; *copy = *dev;
copy->path = NULL; copy->path = NULL;
copy->used_by_drvname = copy->used_by_domname = NULL; copy->used_by_drvname = copy->used_by_domname = NULL;
if (VIR_STRDUP(copy->name, dev->name) < 0 || copy->name = g_strdup(dev->name);
VIR_STRDUP(copy->path, dev->path) < 0 || copy->path = g_strdup(dev->path);
VIR_STRDUP(copy->used_by_drvname, dev->used_by_drvname) < 0 || copy->used_by_drvname = g_strdup(dev->used_by_drvname);
VIR_STRDUP(copy->used_by_domname, dev->used_by_domname) < 0) { copy->used_by_domname = g_strdup(dev->used_by_domname);
goto error;
}
return copy; 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_drvname);
VIR_FREE(dev->used_by_domname); VIR_FREE(dev->used_by_domname);
if (VIR_STRDUP(dev->used_by_drvname, drv_name) < 0) dev->used_by_drvname = g_strdup(drv_name);
return -1; dev->used_by_domname = g_strdup(dom_name);
if (VIR_STRDUP(dev->used_by_domname, dom_name) < 0)
return -1;
return 0; return 0;
} }
@ -2503,8 +2494,7 @@ virPCIGetNetName(const char *device_link_sysfs_path,
continue; continue;
} }
if (VIR_STRDUP(*netname, entry->d_name) < 0) *netname = g_strdup(entry->d_name);
goto cleanup;
ret = 0; ret = 0;
break; break;

View File

@ -111,15 +111,9 @@ virPortAllocatorRangeNew(const char *name,
range->start = start; range->start = start;
range->end = end; range->end = end;
range->name = g_strdup(name);
if (VIR_STRDUP(range->name, name) < 0)
goto error;
return range; return range;
error:
virPortAllocatorRangeFree(range);
return NULL;
} }
void void

View File

@ -2339,8 +2339,7 @@ virResctrlAllocDeterminePath(virResctrlAllocPtr alloc,
/* If the allocation is empty, then the path will be SYSFS_RESCTRL_PATH */ /* If the allocation is empty, then the path will be SYSFS_RESCTRL_PATH */
if (virResctrlAllocIsEmpty(alloc)) { if (virResctrlAllocIsEmpty(alloc)) {
if (VIR_STRDUP(alloc->path, SYSFS_RESCTRL_PATH) < 0) alloc->path = g_strdup(SYSFS_RESCTRL_PATH);
return -1;
return 0; return 0;
} }
@ -2563,8 +2562,7 @@ virResctrlMonitorDeterminePath(virResctrlMonitorPtr monitor,
if (!virResctrlAllocIsEmpty(monitor->alloc) && if (!virResctrlAllocIsEmpty(monitor->alloc) &&
STREQ_NULLABLE(monitor->id, monitor->alloc->id)) { STREQ_NULLABLE(monitor->id, monitor->alloc->id)) {
if (VIR_STRDUP(monitor->path, monitor->alloc->path) < 0) monitor->path = g_strdup(monitor->alloc->path);
return -1;
return 0; return 0;
} }

View File

@ -170,8 +170,7 @@ virRotatingFileReaderEntryNew(const char *path)
entry->inode = sb.st_ino; entry->inode = sb.st_ino;
} }
if (VIR_STRDUP(entry->path, path) < 0) entry->path = g_strdup(path);
goto error;
return entry; return entry;
@ -243,8 +242,7 @@ virRotatingFileWriterNew(const char *path,
if (VIR_ALLOC(file) < 0) if (VIR_ALLOC(file) < 0)
goto error; goto error;
if (VIR_STRDUP(file->basepath, path) < 0) file->basepath = g_strdup(path);
goto error;
if (maxbackup > VIR_MAX_MAX_BACKUP) { if (maxbackup > VIR_MAX_MAX_BACKUP) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
@ -389,8 +387,7 @@ virRotatingFileWriterRollover(virRotatingFileWriterPtr file)
for (i = file->maxbackup; i > 0; i--) { for (i = file->maxbackup; i > 0; i--) {
if (i == 1) { if (i == 1) {
if (VIR_STRDUP(thispath, file->basepath) < 0) thispath = g_strdup(file->basepath);
goto cleanup;
} else { } else {
if (virAsprintf(&thispath, "%s.%zu", file->basepath, i - 2) < 0) if (virAsprintf(&thispath, "%s.%zu", file->basepath, i - 2) < 0)
goto cleanup; goto cleanup;

View File

@ -277,9 +277,8 @@ virSCSIDeviceSetUsedBy(virSCSIDevicePtr dev,
if (VIR_ALLOC(copy) < 0) if (VIR_ALLOC(copy) < 0)
return -1; return -1;
if (VIR_STRDUP(copy->drvname, drvname) < 0 || copy->drvname = g_strdup(drvname);
VIR_STRDUP(copy->domname, domname) < 0) copy->domname = g_strdup(domname);
return -1;
if (VIR_APPEND_ELEMENT(dev->used_by, dev->n_used_by, copy) < 0) if (VIR_APPEND_ELEMENT(dev->used_by, dev->n_used_by, copy) < 0)
return -1; return -1;

View File

@ -205,10 +205,8 @@ virSCSIVHostDeviceSetUsedBy(virSCSIVHostDevicePtr dev,
{ {
VIR_FREE(dev->used_by_drvname); VIR_FREE(dev->used_by_drvname);
VIR_FREE(dev->used_by_domname); VIR_FREE(dev->used_by_domname);
if (VIR_STRDUP(dev->used_by_drvname, drvname) < 0) dev->used_by_drvname = g_strdup(drvname);
return -1; dev->used_by_domname = g_strdup(domname);
if (VIR_STRDUP(dev->used_by_domname, domname) < 0)
return -1;
return 0; return 0;
} }
@ -256,12 +254,7 @@ virSCSIVHostDeviceNew(const char *name)
if (VIR_ALLOC(dev) < 0) if (VIR_ALLOC(dev) < 0)
return NULL; return NULL;
if (VIR_STRDUP(dev->name, name) < 0) { dev->name = g_strdup(name);
virReportError(VIR_ERR_INTERNAL_ERROR,
_("dev->name buffer overflow: %s"),
name);
return NULL;
}
if (virAsprintf(&dev->path, "%s/%s", if (virAsprintf(&dev->path, "%s/%s",
SYSFS_VHOST_SCSI_DEVICES, name) < 0) SYSFS_VHOST_SCSI_DEVICES, name) < 0)

View File

@ -58,12 +58,13 @@ virSecurityLabelDefNew(const char *model)
{ {
virSecurityLabelDefPtr seclabel = NULL; virSecurityLabelDefPtr seclabel = NULL;
if (VIR_ALLOC(seclabel) < 0 || if (VIR_ALLOC(seclabel) < 0) {
VIR_STRDUP(seclabel->model, model) < 0) {
virSecurityLabelDefFree(seclabel); virSecurityLabelDefFree(seclabel);
return NULL; return NULL;
} }
seclabel->model = g_strdup(model);
seclabel->relabel = true; seclabel->relabel = true;
return seclabel; return seclabel;
@ -74,12 +75,13 @@ virSecurityDeviceLabelDefNew(const char *model)
{ {
virSecurityDeviceLabelDefPtr seclabel = NULL; virSecurityDeviceLabelDefPtr seclabel = NULL;
if (VIR_ALLOC(seclabel) < 0 || if (VIR_ALLOC(seclabel) < 0) {
VIR_STRDUP(seclabel->model, model) < 0) {
virSecurityDeviceLabelDefFree(seclabel); virSecurityDeviceLabelDefFree(seclabel);
seclabel = NULL; seclabel = NULL;
} }
seclabel->model = g_strdup(model);
return seclabel; return seclabel;
} }
@ -95,13 +97,8 @@ virSecurityDeviceLabelDefCopy(const virSecurityDeviceLabelDef *src)
ret->relabel = src->relabel; ret->relabel = src->relabel;
ret->labelskip = src->labelskip; ret->labelskip = src->labelskip;
if (VIR_STRDUP(ret->model, src->model) < 0 || ret->model = g_strdup(src->model);
VIR_STRDUP(ret->label, src->label) < 0) ret->label = g_strdup(src->label);
goto error;
return ret; return ret;
error:
virSecurityDeviceLabelDefFree(ret);
return NULL;
} }

View File

@ -55,8 +55,7 @@ virSecretLookupDefCopy(virSecretLookupTypeDefPtr dst,
if (dst->type == VIR_SECRET_LOOKUP_TYPE_UUID) { if (dst->type == VIR_SECRET_LOOKUP_TYPE_UUID) {
memcpy(dst->u.uuid, src->u.uuid, VIR_UUID_BUFLEN); memcpy(dst->u.uuid, src->u.uuid, VIR_UUID_BUFLEN);
} else if (dst->type == VIR_SECRET_LOOKUP_TYPE_USAGE) { } else if (dst->type == VIR_SECRET_LOOKUP_TYPE_USAGE) {
if (VIR_STRDUP(dst->u.usage, src->u.usage) < 0) dst->u.usage = g_strdup(src->u.usage);
return -1;
} }
return 0; return 0;
} }

View File

@ -481,8 +481,7 @@ virSocketAddrFormatFull(const virSocketAddr *addr,
separator ? separator : ":") < 0) separator ? separator : ":") < 0)
return NULL; return NULL;
} else { } else {
if (VIR_STRDUP(addrstr, VIR_LOOPBACK_IPV4_ADDR) < 0) addrstr = g_strdup(VIR_LOOPBACK_IPV4_ADDR);
return NULL;
} }
return addrstr; return addrstr;
} }
@ -515,8 +514,7 @@ virSocketAddrFormatFull(const virSocketAddr *addr,
return NULL; return NULL;
} }
} else { } else {
if (VIR_STRDUP(addrstr, host) < 0) addrstr = g_strdup(host);
return NULL;
} }
return addrstr; return addrstr;

View File

@ -102,8 +102,7 @@ virStringSplitCount(const char *string,
if (VIR_RESIZE_N(tokens, maxtokens, ntokens, 1) < 0) if (VIR_RESIZE_N(tokens, maxtokens, ntokens, 1) < 0)
goto error; goto error;
if (VIR_STRDUP(tokens[ntokens], remainder) < 0) tokens[ntokens] = g_strdup(remainder);
goto error;
ntokens++; ntokens++;
} }
@ -182,10 +181,11 @@ virStringListAdd(char ***strings,
{ {
size_t i = virStringListLength((const char **) *strings); size_t i = virStringListLength((const char **) *strings);
if (VIR_EXPAND_N(*strings, i, 2) < 0 || if (VIR_EXPAND_N(*strings, i, 2) < 0)
VIR_STRDUP((*strings)[i - 2], item) < 0)
return -1; return -1;
(*strings)[i - 2] = g_strdup(item);
return 0; return 0;
} }
@ -286,10 +286,8 @@ virStringListCopy(char ***dst,
if (VIR_ALLOC_N(copy, virStringListLength(src) + 1) < 0) if (VIR_ALLOC_N(copy, virStringListLength(src) + 1) < 0)
goto error; goto error;
for (i = 0; src[i]; i++) { for (i = 0; src[i]; i++)
if (VIR_STRDUP(copy[i], src[i]) < 0) copy[i] = g_strdup(src[i]);
goto error;
}
*dst = copy; *dst = copy;
return 0; return 0;

View File

@ -420,8 +420,7 @@ virSysinfoParseARMProcessor(const char *base, virSysinfoDefPtr ret)
cur, eol - cur) < 0) cur, eol - cur) < 0)
goto error; goto error;
if (VIR_STRDUP(processor->processor_type, processor_type) < 0) processor->processor_type = g_strdup(processor_type);
goto error;
base = cur; base = cur;
} }
@ -558,8 +557,7 @@ virSysinfoParseS390Processor(const char *base, virSysinfoDefPtr ret)
if (VIR_EXPAND_N(ret->processor, ret->nprocessor, 1) < 0) if (VIR_EXPAND_N(ret->processor, ret->nprocessor, 1) < 0)
goto error; goto error;
processor = &ret->processor[ret->nprocessor - 1]; processor = &ret->processor[ret->nprocessor - 1];
if (VIR_STRDUP(processor->processor_manufacturer, manufacturer) < 0) processor->processor_manufacturer = g_strdup(manufacturer);
goto error;
if (!virSysinfoParseS390Delimited(procline, "version", if (!virSysinfoParseS390Delimited(procline, "version",
&processor->processor_version, &processor->processor_version,
'=', ',') || '=', ',') ||

View File

@ -308,8 +308,7 @@ int virSystemdCreateMachine(const char *name,
if (!(slicename = virSystemdMakeSliceName(partition))) if (!(slicename = virSystemdMakeSliceName(partition)))
goto cleanup; goto cleanup;
} else { } else {
if (VIR_STRDUP(slicename, "") < 0) slicename = g_strdup("");
goto cleanup;
} }
/* /*

View File

@ -104,8 +104,7 @@ virTypedParameterAssignFromStr(virTypedParameterPtr param,
} }
break; break;
case VIR_TYPED_PARAM_STRING: case VIR_TYPED_PARAM_STRING:
if (VIR_STRDUP(param->value.s, val) < 0) param->value.s = g_strdup(val);
return -1;
break; break;
default: default:
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
@ -736,8 +735,7 @@ virTypedParamsAddString(virTypedParameterPtr *params,
goto error; goto error;
*maxparams = max; *maxparams = max;
if (VIR_STRDUP(str, value) < 0) str = g_strdup(value);
goto error;
if (virTypedParameterAssign(*params + n, name, if (virTypedParameterAssign(*params + n, name,
VIR_TYPED_PARAM_STRING, str) < 0) { VIR_TYPED_PARAM_STRING, str) < 0) {

View File

@ -234,8 +234,7 @@ virTypedParameterAssignValueVArgs(virTypedParameterPtr param,
break; break;
case VIR_TYPED_PARAM_STRING: case VIR_TYPED_PARAM_STRING:
if (copystr) { if (copystr) {
if (VIR_STRDUP(param->value.s, va_arg(ap, char *)) < 0) param->value.s = g_strdup(va_arg(ap, char *));
return -1;
} else { } else {
param->value.s = va_arg(ap, char *); param->value.s = va_arg(ap, char *);
} }
@ -337,8 +336,7 @@ virTypedParamsReplaceString(virTypedParameterPtr *params,
param = *params + n - 1; param = *params + n - 1;
} }
if (VIR_STRDUP(str, value) < 0) str = g_strdup(value);
goto error;
if (virTypedParameterAssign(param, name, if (virTypedParameterAssign(param, name,
VIR_TYPED_PARAM_STRING, str) < 0) { VIR_TYPED_PARAM_STRING, str) < 0) {
@ -374,11 +372,7 @@ virTypedParamsCopy(virTypedParameterPtr *dst,
ignore_value(virStrcpyStatic((*dst)[i].field, src[i].field)); ignore_value(virStrcpyStatic((*dst)[i].field, src[i].field));
(*dst)[i].type = src[i].type; (*dst)[i].type = src[i].type;
if (src[i].type == VIR_TYPED_PARAM_STRING) { if (src[i].type == VIR_TYPED_PARAM_STRING) {
if (VIR_STRDUP((*dst)[i].value.s, src[i].value.s) < 0) { (*dst)[i].value.s = g_strdup(src[i].value.s);
virTypedParamsFree(*dst, i - 1);
*dst = NULL;
return -1;
}
} else { } else {
(*dst)[i].value = src[i].value; (*dst)[i].value = src[i].value;
} }
@ -613,9 +607,7 @@ virTypedParamsDeserialize(virTypedParameterRemotePtr remote_params,
remote_param->value.remote_typed_param_value.b; remote_param->value.remote_typed_param_value.b;
break; break;
case VIR_TYPED_PARAM_STRING: case VIR_TYPED_PARAM_STRING:
if (VIR_STRDUP(param->value.s, param->value.s = g_strdup(remote_param->value.remote_typed_param_value.s);
remote_param->value.remote_typed_param_value.s) < 0)
goto cleanup;
break; break;
default: default:
virReportError(VIR_ERR_RPC, _("unknown parameter type: %d"), virReportError(VIR_ERR_RPC, _("unknown parameter type: %d"),
@ -699,8 +691,7 @@ virTypedParamsSerialize(virTypedParameterPtr params,
/* This will be either freed by virNetServerDispatchCall or call(), /* This will be either freed by virNetServerDispatchCall or call(),
* depending on the calling side, i.e. server or client */ * depending on the calling side, i.e. server or client */
if (VIR_STRDUP(val->field, param->field) < 0) val->field = g_strdup(param->field);
goto cleanup;
val->value.type = param->type; val->value.type = param->type;
switch (param->type) { switch (param->type) {
case VIR_TYPED_PARAM_INT: case VIR_TYPED_PARAM_INT:
@ -722,8 +713,7 @@ virTypedParamsSerialize(virTypedParameterPtr params,
val->value.remote_typed_param_value.b = param->value.b; val->value.remote_typed_param_value.b = param->value.b;
break; break;
case VIR_TYPED_PARAM_STRING: case VIR_TYPED_PARAM_STRING:
if (VIR_STRDUP(val->value.remote_typed_param_value.s, param->value.s) < 0) val->value.remote_typed_param_value.s = g_strdup(param->value.s);
goto cleanup;
break; break;
default: default:
virReportError(VIR_ERR_RPC, _("unknown parameter type: %d"), virReportError(VIR_ERR_RPC, _("unknown parameter type: %d"),

View File

@ -41,8 +41,8 @@ virURIParamAppend(virURIPtr uri,
char *pname = NULL; char *pname = NULL;
char *pvalue = NULL; char *pvalue = NULL;
if (VIR_STRDUP(pname, name) < 0 || VIR_STRDUP(pvalue, value) < 0) pname = g_strdup(name);
goto error; pvalue = g_strdup(value);
if (VIR_RESIZE_N(uri->params, uri->paramsAlloc, uri->paramsCount, 1) < 0) if (VIR_RESIZE_N(uri->params, uri->paramsAlloc, uri->paramsCount, 1) < 0)
goto error; goto error;
@ -167,10 +167,8 @@ virURIParse(const char *uri)
if (VIR_ALLOC(ret) < 0) if (VIR_ALLOC(ret) < 0)
goto error; goto error;
if (VIR_STRDUP(ret->scheme, xmluri->scheme) < 0) ret->scheme = g_strdup(xmluri->scheme);
goto error; ret->server = g_strdup(xmluri->server);
if (VIR_STRDUP(ret->server, xmluri->server) < 0)
goto error;
/* xmluri->port value is not defined if server was /* xmluri->port value is not defined if server was
* not given. Modern versions libxml2 fill port * not given. Modern versions libxml2 fill port
* differently to old versions in this case, so * differently to old versions in this case, so
@ -181,14 +179,10 @@ virURIParse(const char *uri)
ret->port = 0; ret->port = 0;
else else
ret->port = xmluri->port; ret->port = xmluri->port;
if (VIR_STRDUP(ret->path, xmluri->path) < 0) ret->path = g_strdup(xmluri->path);
goto error; ret->query = g_strdup(xmluri->query_raw);
if (VIR_STRDUP(ret->query, xmluri->query_raw) < 0) ret->fragment = g_strdup(xmluri->fragment);
goto error; ret->user = g_strdup(xmluri->user);
if (VIR_STRDUP(ret->fragment, xmluri->fragment) < 0)
goto error;
if (VIR_STRDUP(ret->user, xmluri->user) < 0)
goto error;
/* Strip square bracket from an IPv6 address. /* Strip square bracket from an IPv6 address.
* The function modifies the string in-place. Even after such * The function modifies the string in-place. Even after such

View File

@ -379,10 +379,8 @@ virUSBDeviceSetUsedBy(virUSBDevicePtr dev,
{ {
VIR_FREE(dev->used_by_drvname); VIR_FREE(dev->used_by_drvname);
VIR_FREE(dev->used_by_domname); VIR_FREE(dev->used_by_domname);
if (VIR_STRDUP(dev->used_by_drvname, drv_name) < 0) dev->used_by_drvname = g_strdup(drv_name);
return -1; dev->used_by_domname = g_strdup(dom_name);
if (VIR_STRDUP(dev->used_by_domname, dom_name) < 0)
return -1;
return 0; return 0;
} }

View File

@ -646,14 +646,14 @@ virGetUserEnt(uid_t uid, char **name, gid_t *group, char **dir, char **shell, bo
goto cleanup; goto cleanup;
} }
if (name && VIR_STRDUP(*name, pw->pw_name) < 0) if (name)
goto cleanup; *name = g_strdup(pw->pw_name);
if (group) if (group)
*group = pw->pw_gid; *group = pw->pw_gid;
if (dir && VIR_STRDUP(*dir, pw->pw_dir) < 0) if (dir)
goto cleanup; *dir = g_strdup(pw->pw_dir);
if (shell && VIR_STRDUP(*shell, pw->pw_shell) < 0) if (shell)
goto cleanup; *shell = g_strdup(pw->pw_shell);
ret = 0; ret = 0;
cleanup: cleanup:
@ -1094,8 +1094,8 @@ virGetWin32SpecialFolder(int csidl, char **path)
*path = NULL; *path = NULL;
if (SHGetSpecialFolderLocation(NULL, csidl, &pidl) == S_OK) { if (SHGetSpecialFolderLocation(NULL, csidl, &pidl) == S_OK) {
if (SHGetPathFromIDList(pidl, buf) && VIR_STRDUP(*path, buf) < 0) if (SHGetPathFromIDList(pidl, buf))
ret = -1; *path = g_strdup(buf);
CoTaskMemFree(pidl); CoTaskMemFree(pidl);
} }
return ret; return ret;
@ -1123,7 +1123,8 @@ virGetWin32DirectoryRoot(char **path)
strcpy(windowsdir, "C:\\"); 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? */ /* USERPROFILE is probably the closest equivalent to $HOME? */
dir = getenv("USERPROFILE"); dir = getenv("USERPROFILE");
if (VIR_STRDUP(ret, dir) < 0) ret = g_strdup(dir);
return NULL;
if (!ret && if (!ret &&
virGetWin32SpecialFolder(CSIDL_PROFILE, &ret) < 0) virGetWin32SpecialFolder(CSIDL_PROFILE, &ret) < 0)
@ -1687,8 +1687,7 @@ virParseOwnershipIds(const char *label, uid_t *uidPtr, gid_t *gidPtr)
char *owner = NULL; char *owner = NULL;
char *group = NULL; char *group = NULL;
if (VIR_STRDUP(tmp_label, label) < 0) tmp_label = g_strdup(label);
goto cleanup;
/* Split label */ /* Split label */
sep = strchr(tmp_label, ':'); sep = strchr(tmp_label, ':');

View File

@ -1260,8 +1260,7 @@ virXMLValidatorInit(const char *schemafile)
if (VIR_ALLOC(validator) < 0) if (VIR_ALLOC(validator) < 0)
return NULL; return NULL;
if (VIR_STRDUP(validator->schemafile, schemafile) < 0) validator->schemafile = g_strdup(schemafile);
goto error;
if (!(validator->rngParser = if (!(validator->rngParser =
xmlRelaxNGNewParserCtxt(validator->schemafile))) { xmlRelaxNGNewParserCtxt(validator->schemafile))) {