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;
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++;
}

View 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;
}

View 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;

View 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);
}

View 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;

View 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,

View 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:

View 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;
/*

View 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;
}

View 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;
}

View 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;

View 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;

View 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

View 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]);
}
}

View 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,

View 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;

View 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;

View 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,

View 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) */

View 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"));

View 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);

View 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);

View 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 ||

View 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:

View 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) &&

View 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);

View 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;

View 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;

View 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

View 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;
}

View 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;

View 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;

View 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)

View 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;
}

View 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;
}

View 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;

View 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;

View 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,
'=', ',') ||

View 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("");
}
/*

View 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) {

View 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"),

View 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

View 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;
}

View 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, ':');

View 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))) {