1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-22 17:34:18 +03:00

tests: 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 ddb99ca516
commit 29b1e859e3
39 changed files with 115 additions and 222 deletions

View File

@ -34,8 +34,7 @@ int virNetDevTapCreateInBridgePort(const char *brname G_GNUC_UNUSED,
unsigned int fakeflags G_GNUC_UNUSED)
{
VIR_FREE(*ifname);
if (VIR_STRDUP(*ifname, "vnet0") < 0)
return -1;
*ifname = g_strdup("vnet0");
return 0;
}
@ -43,8 +42,7 @@ char *virNetDevTapGetRealDeviceName(char *name G_GNUC_UNUSED)
{
char *fakename;
if (VIR_STRDUP(fakename, "faketapdev") < 0)
return NULL;
fakename = g_strdup("faketapdev");
return fakename;
}

View File

@ -686,10 +686,7 @@ static int test17(const void *unused G_GNUC_UNUSED)
goto cleanup;
}
VIR_FREE(outbuf);
if (VIR_STRDUP(outbuf, "should not be leaked") < 0) {
puts("test framework failure");
goto cleanup;
}
outbuf = g_strdup("should not be leaked");
virCommandSetErrorBuffer(cmd, &errbuf);
if (errbuf != NULL) {

View File

@ -492,9 +492,11 @@ cpuTestMakeQEMUCaps(const struct data *data)
if (!(testMon = qemuMonitorTestNewFromFile(json, driver.xmlopt, true)))
goto error;
if (VIR_ALLOC(cpu) < 0 || VIR_STRDUP(cpu->model, "host") < 0)
if (VIR_ALLOC(cpu) < 0)
goto cleanup;
cpu->model = g_strdup("host");
if (ARCH_IS_S390(data->arch))
fail_no_props = false;

View File

@ -36,11 +36,11 @@ fillStringValues(virDomainCapsStringValuesPtr values, ...)
va_start(list, values);
while ((str = va_arg(list, const char *))) {
if (VIR_REALLOC_N(values->values, values->nvalues + 1) < 0 ||
VIR_STRDUP(values->values[values->nvalues], str) < 0) {
if (VIR_REALLOC_N(values->values, values->nvalues + 1) < 0) {
ret = -1;
break;
}
values->values[values->nvalues] = g_strdup(str);
values->nvalues++;
}
va_end(list);
@ -95,9 +95,7 @@ fillQemuCaps(virDomainCapsPtr domCaps,
if (machine) {
VIR_FREE(domCaps->machine);
if (VIR_STRDUP(domCaps->machine,
virQEMUCapsGetCanonicalMachine(qemuCaps, machine)) < 0)
goto cleanup;
domCaps->machine = g_strdup(virQEMUCapsGetCanonicalMachine(qemuCaps, machine));
}
if (!domCaps->machine)
@ -153,9 +151,8 @@ fillXenCaps(virDomainCapsPtr domCaps)
if (VIR_ALLOC(firmwares[0]) < 0 || VIR_ALLOC(firmwares[1]) < 0)
goto cleanup;
if (VIR_STRDUP(firmwares[0]->name, "/usr/lib/xen/boot/hvmloader") < 0 ||
VIR_STRDUP(firmwares[1]->name, "/usr/lib/xen/boot/ovmf.bin") < 0)
goto cleanup;
firmwares[0]->name = g_strdup("/usr/lib/xen/boot/hvmloader");
firmwares[1]->name = g_strdup("/usr/lib/xen/boot/ovmf.bin");
if (libxlMakeDomainCapabilities(domCaps, firmwares, 2) < 0)
goto cleanup;

View File

@ -62,8 +62,7 @@ getrealpath(char **newpath,
return -1;
}
} else {
if (VIR_STRDUP_QUIET(*newpath, path) < 0)
return -1;
*newpath = g_strdup(path);
}
return 0;

View File

@ -99,10 +99,11 @@ testReadNetworkConf(const void *data G_GNUC_UNUSED)
" </devices>\n"
"</domain>\n";
if (!(def = virDomainDefNew()) ||
VIR_STRDUP(def->os.init, "/sbin/init") < 0)
if (!(def = virDomainDefNew()))
goto cleanup;
def->os.init = g_strdup("/sbin/init");
def->virtType = VIR_DOMAIN_VIRT_OPENVZ;
def->os.type = VIR_DOMAIN_OSTYPE_EXE;

View File

@ -161,8 +161,7 @@ testQemuDiskXMLToJSONFakeSecrets(virStorageSourcePtr src)
return -1;
srcpriv->secinfo->type = VIR_DOMAIN_SECRET_INFO_TYPE_AES;
if (VIR_STRDUP(srcpriv->secinfo->s.aes.username, src->auth->username) < 0)
return -1;
srcpriv->secinfo->s.aes.username = g_strdup(src->auth->username);
if (virAsprintf(&srcpriv->secinfo->s.aes.alias, "%s-secalias",
NULLSTR(src->nodestorage)) < 0)

View File

@ -63,8 +63,7 @@ testCompareXMLToXMLFiles(const char *inxml,
if (flags & TEST_PARENT) {
if (def->parent.parent_name)
return -1;
if (VIR_STRDUP(def->parent.parent_name, "1525111885") < 0)
return -1;
def->parent.parent_name = g_strdup("1525111885");
}
if (flags & TEST_VDA_BITMAP) {
virDomainCheckpointDiskDefPtr disk;
@ -76,13 +75,11 @@ testCompareXMLToXMLFiles(const char *inxml,
return -1;
if (!disk->name) {
disk->type = VIR_DOMAIN_CHECKPOINT_TYPE_BITMAP;
if (VIR_STRDUP(disk->name, "vda") < 0)
return -1;
disk->name = g_strdup("vda");
} else if (STRNEQ(disk->name, "vda")) {
return -1;
}
if (VIR_STRDUP(disk->bitmap, def->parent.name) < 0)
return -1;
disk->bitmap = g_strdup(def->parent.name);
}
if (flags & TEST_SIZE) {
def->disks[0].size = 1048576;

View File

@ -70,8 +70,7 @@ testFWPrecedence(const void *opaque G_GNUC_UNUSED)
};
const size_t nexpected = G_N_ELEMENTS(expected);
if (VIR_STRDUP(fakehome, abs_srcdir "/qemufirmwaredata/home/user/.config") < 0)
return -1;
fakehome = g_strdup(abs_srcdir "/qemufirmwaredata/home/user/.config");
setenv("XDG_CONFIG_HOME", fakehome, 1);

View File

@ -597,10 +597,7 @@ mymain(void)
struct testQemuHotplugCpuParams cpudata;
char *fakerootdir;
if (VIR_STRDUP_QUIET(fakerootdir, FAKEROOTDIRTEMPLATE) < 0) {
fprintf(stderr, "Out of memory\n");
abort();
}
fakerootdir = g_strdup(FAKEROOTDIRTEMPLATE);
if (!mkdtemp(fakerootdir)) {
fprintf(stderr, "Cannot create fakerootdir");
@ -622,8 +619,7 @@ mymain(void)
VIR_FREE(driver.config->spiceListen);
VIR_FREE(driver.config->vncListen);
/* some dummy values from 'config file' */
if (VIR_STRDUP_QUIET(driver.config->spicePassword, "123456") < 0)
return EXIT_FAILURE;
driver.config->spicePassword = g_strdup("123456");
if (!(driver.domainEventState = virObjectEventStateNew()))
return EXIT_FAILURE;

View File

@ -61,10 +61,7 @@ mymain(void)
char *fakerootdir;
virQEMUCapsPtr qemuCaps = NULL;
if (VIR_STRDUP_QUIET(fakerootdir, FAKEROOTDIRTEMPLATE) < 0) {
fprintf(stderr, "Out of memory\n");
abort();
}
fakerootdir = g_strdup(FAKEROOTDIRTEMPLATE);
if (!mkdtemp(fakerootdir)) {
fprintf(stderr, "Cannot create fakerootdir");

View File

@ -2165,8 +2165,7 @@ testQemuMonitorJSONqemuMonitorJSONSetBlockIoThrottle(const void *opaque)
return -1;
expectedInfo = (virDomainBlockIoTuneInfo) {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, NULL, 15, 16, 17, 18, 19, 20};
if (VIR_STRDUP(expectedInfo.group_name, "group14") < 0)
return -1;
expectedInfo.group_name = g_strdup("group14");
if (qemuMonitorTestAddItem(test, "query-block", queryBlockReply) < 0 ||
qemuMonitorTestAddItemParams(test, "block_set_io_throttle",

View File

@ -604,11 +604,8 @@ qemuMonitorTestAddItem(qemuMonitorTestPtr test,
if (VIR_ALLOC(data) < 0)
return -1;
if (VIR_STRDUP(data->command_name, command_name) < 0 ||
VIR_STRDUP(data->response, response) < 0) {
qemuMonitorTestHandlerDataFree(data);
return -1;
}
data->command_name = g_strdup(command_name);
data->response = g_strdup(response);
return qemuMonitorTestAddHandler(test,
qemuMonitorTestProcessCommandDefault,
@ -692,9 +689,8 @@ qemuMonitorTestAddItemVerbatim(qemuMonitorTestPtr test,
if (VIR_ALLOC(data) < 0)
return -1;
if (VIR_STRDUP(data->response, response) < 0 ||
VIR_STRDUP(data->cmderr, cmderr) < 0)
goto error;
data->response = g_strdup(response);
data->cmderr = g_strdup(cmderr);
data->command_name = virJSONStringReformat(command, false);
if (!data->command_name)
@ -868,9 +864,8 @@ qemuMonitorTestAddItemParams(qemuMonitorTestPtr test,
if (VIR_ALLOC(data) < 0)
goto error;
if (VIR_STRDUP(data->command_name, cmdname) < 0 ||
VIR_STRDUP(data->response, response) < 0)
goto error;
data->command_name = g_strdup(cmdname);
data->response = g_strdup(response);
while ((argname = va_arg(args, char *))) {
size_t i;
@ -885,9 +880,8 @@ qemuMonitorTestAddItemParams(qemuMonitorTestPtr test,
if (VIR_EXPAND_N(data->args, data->nargs, 1))
goto error;
if (VIR_STRDUP(data->args[i].argname, argname) < 0 ||
VIR_STRDUP(data->args[i].argval, argval) < 0)
goto error;
data->args[i].argname = g_strdup(argname);
data->args[i].argval = g_strdup(argval);
}
va_end(args);
@ -984,10 +978,9 @@ qemuMonitorTestAddItemExpect(qemuMonitorTestPtr test,
if (VIR_ALLOC(data) < 0)
goto error;
if (VIR_STRDUP(data->command_name, cmdname) < 0 ||
VIR_STRDUP(data->response, response) < 0 ||
VIR_STRDUP(data->expectArgs, cmdargs) < 0)
goto error;
data->command_name = g_strdup(cmdname);
data->response = g_strdup(response);
data->expectArgs = g_strdup(cmdargs);
if (apostrophe) {
char *tmp = data->expectArgs;
@ -1065,8 +1058,7 @@ qemuMonitorCommonTestNew(virDomainXMLOptionPtr xmlopt,
return NULL;
}
if (VIR_STRDUP(tmpdir_template, "/tmp/libvirt_XXXXXX") < 0)
goto error;
tmpdir_template = g_strdup("/tmp/libvirt_XXXXXX");
if (!(test->tmpdir = mkdtemp(tmpdir_template))) {
virReportSystemError(errno, "%s",

View File

@ -146,8 +146,7 @@ virFileGetXAttrQuiet(const char *path,
goto cleanup;
}
if (VIR_STRDUP(*value, val) < 0)
goto cleanup;
*value = g_strdup(val);
ret = 0;
cleanup:
@ -194,8 +193,7 @@ int virFileSetXAttr(const char *path,
char *val;
key = get_key(path, name);
if (VIR_STRDUP(val, value) < 0)
return -1;
val = g_strdup(value);
virMutexLock(&m);
init_syms();

View File

@ -68,8 +68,7 @@ testVUPrecedence(const void *opaque G_GNUC_UNUSED)
};
const size_t nexpected = G_N_ELEMENTS(expected);
if (VIR_STRDUP(fakehome, abs_srcdir "/qemuvhostuserdata/home/user/.config") < 0)
return -1;
fakehome = g_strdup(abs_srcdir "/qemuvhostuserdata/home/user/.config");
setenv("XDG_CONFIG_HOME", fakehome, 1);

View File

@ -43,8 +43,7 @@ fakeSecretGetValue(virSecretPtr obj G_GNUC_UNUSED,
unsigned int internalFlags G_GNUC_UNUSED)
{
char *secret;
if (VIR_STRDUP(secret, "AQCVn5hO6HzFAhAAq0NCv8jtJcIcE+HOBlMQ1A") < 0)
return NULL;
secret = g_strdup("AQCVn5hO6HzFAhAAq0NCv8jtJcIcE+HOBlMQ1A");
*value_size = strlen(secret);
return (unsigned char *) secret;
}
@ -517,9 +516,7 @@ testCompareXMLToArgv(const void *data)
switch (vm->def->tpm->type) {
case VIR_DOMAIN_TPM_TYPE_EMULATOR:
VIR_FREE(vm->def->tpm->data.emulator.source.data.file.path);
if (VIR_STRDUP(vm->def->tpm->data.emulator.source.data.file.path,
"/dev/test") < 0)
goto cleanup;
vm->def->tpm->data.emulator.source.data.file.path = g_strdup("/dev/test");
vm->def->tpm->data.emulator.source.type = VIR_DOMAIN_CHR_TYPE_FILE;
break;
case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH:
@ -620,10 +617,7 @@ mymain(void)
char *fakerootdir;
virHashTablePtr capslatest = NULL;
if (VIR_STRDUP_QUIET(fakerootdir, FAKEROOTDIRTEMPLATE) < 0) {
fprintf(stderr, "Out of memory\n");
abort();
}
fakerootdir = g_strdup(FAKEROOTDIRTEMPLATE);
if (!mkdtemp(fakerootdir)) {
fprintf(stderr, "Cannot create fakerootdir");
@ -648,43 +642,33 @@ mymain(void)
driver.privileged = true;
VIR_FREE(driver.config->defaultTLSx509certdir);
if (VIR_STRDUP_QUIET(driver.config->defaultTLSx509certdir, "/etc/pki/qemu") < 0)
return EXIT_FAILURE;
driver.config->defaultTLSx509certdir = g_strdup("/etc/pki/qemu");
VIR_FREE(driver.config->vncTLSx509certdir);
if (VIR_STRDUP_QUIET(driver.config->vncTLSx509certdir, "/etc/pki/libvirt-vnc") < 0)
return EXIT_FAILURE;
driver.config->vncTLSx509certdir = g_strdup("/etc/pki/libvirt-vnc");
VIR_FREE(driver.config->spiceTLSx509certdir);
if (VIR_STRDUP_QUIET(driver.config->spiceTLSx509certdir, "/etc/pki/libvirt-spice") < 0)
return EXIT_FAILURE;
driver.config->spiceTLSx509certdir = g_strdup("/etc/pki/libvirt-spice");
VIR_FREE(driver.config->chardevTLSx509certdir);
if (VIR_STRDUP_QUIET(driver.config->chardevTLSx509certdir, "/etc/pki/libvirt-chardev") < 0)
return EXIT_FAILURE;
driver.config->chardevTLSx509certdir = g_strdup("/etc/pki/libvirt-chardev");
VIR_FREE(driver.config->vxhsTLSx509certdir);
if (VIR_STRDUP_QUIET(driver.config->vxhsTLSx509certdir, "/etc/pki/libvirt-vxhs/dummy,path") < 0)
return EXIT_FAILURE;
driver.config->vxhsTLSx509certdir = g_strdup("/etc/pki/libvirt-vxhs/dummy,path");
VIR_FREE(driver.config->nbdTLSx509certdir);
if (VIR_STRDUP_QUIET(driver.config->nbdTLSx509certdir, "/etc/pki/libvirt-nbd/dummy,path") < 0)
return EXIT_FAILURE;
driver.config->nbdTLSx509certdir = g_strdup("/etc/pki/libvirt-nbd/dummy,path");
VIR_FREE(driver.config->hugetlbfs);
if (VIR_ALLOC_N(driver.config->hugetlbfs, 2) < 0)
return EXIT_FAILURE;
driver.config->nhugetlbfs = 2;
if (VIR_STRDUP(driver.config->hugetlbfs[0].mnt_dir, "/dev/hugepages2M") < 0 ||
VIR_STRDUP(driver.config->hugetlbfs[1].mnt_dir, "/dev/hugepages1G") < 0)
return EXIT_FAILURE;
driver.config->hugetlbfs[0].mnt_dir = g_strdup("/dev/hugepages2M");
driver.config->hugetlbfs[1].mnt_dir = g_strdup("/dev/hugepages1G");
driver.config->hugetlbfs[0].size = 2048;
driver.config->hugetlbfs[0].deflt = true;
driver.config->hugetlbfs[1].size = 1048576;
driver.config->spiceTLS = 1;
if (VIR_STRDUP_QUIET(driver.config->spicePassword, "123456") < 0)
return EXIT_FAILURE;
driver.config->spicePassword = g_strdup("123456");
VIR_FREE(driver.config->memoryBackingDir);
if (VIR_STRDUP_QUIET(driver.config->memoryBackingDir, "/var/lib/libvirt/qemu/ram") < 0)
return EXIT_FAILURE;
driver.config->memoryBackingDir = g_strdup("/var/lib/libvirt/qemu/ram");
VIR_FREE(driver.config->nvramDir);
if (VIR_STRDUP(driver.config->nvramDir, "/var/lib/libvirt/qemu/nvram") < 0)
return EXIT_FAILURE;
driver.config->nvramDir = g_strdup("/var/lib/libvirt/qemu/nvram");
capslatest = testQemuGetLatestCaps();
if (!capslatest)
@ -1222,9 +1206,7 @@ mymain(void)
DO_TEST("graphics-vnc-tls", QEMU_CAPS_VNC, QEMU_CAPS_DEVICE_CIRRUS_VGA);
DO_TEST_CAPS_VER("graphics-vnc-tls", "2.4.0");
DO_TEST_CAPS_LATEST("graphics-vnc-tls");
if (VIR_STRDUP_QUIET(driver.config->vncTLSx509secretUUID,
"6fd3f62d-9fe7-4a4e-a869-7acd6376d8ea") < 0)
return EXIT_FAILURE;
driver.config->vncTLSx509secretUUID = g_strdup("6fd3f62d-9fe7-4a4e-a869-7acd6376d8ea");
DO_TEST_CAPS_LATEST("graphics-vnc-tls-secret");
VIR_FREE(driver.config->vncTLSx509secretUUID);
driver.config->vncSASL = driver.config->vncTLSx509verify = driver.config->vncTLS = 0;
@ -1407,11 +1389,8 @@ mymain(void)
QEMU_CAPS_DEVICE_ISA_SERIAL,
QEMU_CAPS_OBJECT_TLS_CREDS_X509);
VIR_FREE(driver.config->chardevTLSx509certdir);
if (VIR_STRDUP_QUIET(driver.config->chardevTLSx509certdir, "/etc/pki/libvirt-chardev") < 0)
return EXIT_FAILURE;
if (VIR_STRDUP_QUIET(driver.config->chardevTLSx509secretUUID,
"6fd3f62d-9fe7-4a4e-a869-7acd6376d8ea") < 0)
return EXIT_FAILURE;
driver.config->chardevTLSx509certdir = g_strdup("/etc/pki/libvirt-chardev");
driver.config->chardevTLSx509secretUUID = g_strdup("6fd3f62d-9fe7-4a4e-a869-7acd6376d8ea");
DO_TEST("serial-tcp-tlsx509-secret-chardev",
QEMU_CAPS_OBJECT_SECRET,
QEMU_CAPS_DEVICE_ISA_SERIAL,

View File

@ -157,10 +157,7 @@ mymain(void)
if (!capslatest)
return EXIT_FAILURE;
if (VIR_STRDUP_QUIET(fakerootdir, FAKEROOTDIRTEMPLATE) < 0) {
fprintf(stderr, "Out of memory\n");
abort();
}
fakerootdir = g_strdup(FAKEROOTDIRTEMPLATE);
if (!mkdtemp(fakerootdir)) {
fprintf(stderr, "Cannot create fakerootdir");

View File

@ -253,10 +253,7 @@ mymain(void)
char *fakerootdir = NULL;
char *fakesysfsdir = NULL;
if (VIR_STRDUP_QUIET(fakerootdir, FAKEROOTDIRTEMPLATE) < 0) {
fprintf(stderr, "Out of memory\n");
goto cleanup;
}
fakerootdir = g_strdup(FAKEROOTDIRTEMPLATE);
if (!mkdtemp(fakerootdir)) {
fprintf(stderr, "Cannot create fakerootdir");

View File

@ -144,10 +144,7 @@ testSELinuxLoadFileList(const char *testname,
abs_builddir, line) < 0)
goto cleanup;
if (*tmp != '\0' && *tmp != '\n') {
if (VIR_STRDUP(context, tmp) < 0) {
VIR_FREE(file);
goto cleanup;
}
context = g_strdup(tmp);
tmp = strchr(context, '\n');
if (tmp)
@ -270,8 +267,7 @@ testSELinuxCheckLabels(testSELinuxFile *files, size_t nfiles)
if (errno == ENODATA) {
/* nothing to do */
} else if (errno == EOPNOTSUPP) {
if (VIR_STRDUP(ctx, "EOPNOTSUPP") < 0)
return -1;
ctx = g_strdup("EOPNOTSUPP");
} else {
virReportSystemError(errno,
"Cannot read label on %s",

View File

@ -77,17 +77,14 @@ testBuildDomainDef(bool dynamic,
if (VIR_ALLOC(secdef) < 0)
goto error;
if (VIR_STRDUP(secdef->model, "selinux") < 0)
goto error;
secdef->model = g_strdup("selinux");
secdef->type = dynamic ? VIR_DOMAIN_SECLABEL_DYNAMIC : VIR_DOMAIN_SECLABEL_STATIC;
if (label &&
VIR_STRDUP(secdef->label, label) < 0)
goto error;
if (label)
secdef->label = g_strdup(label);
if (baselabel &&
VIR_STRDUP(secdef->baselabel, baselabel) < 0)
goto error;
if (baselabel)
secdef->baselabel = g_strdup(baselabel);
def->seclabels[0] = secdef;
def->nseclabels++;

View File

@ -63,8 +63,7 @@ test_node_info_parser(const void *opaque)
if (!(pool = virStoragePoolDefParseFile(data->poolxml)))
return -1;
if (VIR_STRDUP(output, test.output) < 0)
return -1;
output = g_strdup(test.output);
if (virStorageBackendSheepdogParseNodeInfo(pool, output) !=
test.expected_return)
@ -95,8 +94,7 @@ test_vdi_list_parser(const void *opaque)
if (!(vol = virStorageVolDefParseFile(pool, data->volxml, 0)))
return -1;
if (VIR_STRDUP(output, test.output) < 0)
return -1;
output = g_strdup(test.output);
if (virStorageBackendSheepdogParseVdiList(vol, output) !=
test.expected_return)

View File

@ -816,8 +816,7 @@ virTestSetEnvPath(void)
virAsprintf(&new_path, "%s:%s", abs_builddir, path) < 0)
goto cleanup;
} else {
if (VIR_STRDUP(new_path, abs_builddir) < 0)
goto cleanup;
new_path = g_strdup(abs_builddir);
}
if (new_path &&

View File

@ -74,8 +74,7 @@ static virCapsGuestMachinePtr *testQemuAllocNewerMachines(int *nmachines)
"pc-0.11", "pc", "pc-0.10", "isapc"
};
if (VIR_STRDUP(canonical, x86_machines[0]) < 0)
return NULL;
canonical = g_strdup(x86_machines[0]);
machines = virCapabilitiesAllocMachines(x86_machines,
G_N_ELEMENTS(x86_machines));
@ -503,9 +502,8 @@ virCapsPtr testQemuCapsInit(void)
goto cleanup;
caps->host.nsecModels = 1;
if (VIR_STRDUP(caps->host.secModels[0].model, "none") < 0 ||
VIR_STRDUP(caps->host.secModels[0].doi, "0") < 0)
goto cleanup;
caps->host.secModels[0].model = g_strdup("none");
caps->host.secModels[0].doi = g_strdup("0");
if (!(cpuDefault = virCPUDefCopy(&cpuDefaultData)) ||
!(cpuHaswell = virCPUDefCopy(&cpuHaswellData)) ||
@ -710,29 +708,22 @@ int qemuTestDriverInit(virQEMUDriver *driver)
/* Overwrite some default paths so it's consistent for tests. */
VIR_FREE(driver->config->libDir);
VIR_FREE(driver->config->channelTargetDir);
if (VIR_STRDUP(driver->config->libDir, "/tmp/lib") < 0 ||
VIR_STRDUP(driver->config->channelTargetDir, "/tmp/channel") < 0)
goto error;
driver->config->libDir = g_strdup("/tmp/lib");
driver->config->channelTargetDir = g_strdup("/tmp/channel");
if (!mkdtemp(statedir)) {
virFilePrintf(stderr, "Cannot create fake stateDir");
goto error;
}
if (VIR_STRDUP(driver->config->stateDir, statedir) < 0) {
rmdir(statedir);
goto error;
}
driver->config->stateDir = g_strdup(statedir);
if (!mkdtemp(configdir)) {
virFilePrintf(stderr, "Cannot create fake configDir");
goto error;
}
if (VIR_STRDUP(driver->config->configDir, configdir) < 0) {
rmdir(configdir);
goto error;
}
driver->config->configDir = g_strdup(configdir);
driver->caps = testQemuCapsInit();
if (!driver->caps)
@ -827,10 +818,9 @@ testQemuGetLatestCapsForArch(const char *arch,
while ((rc = virDirRead(dir, &ent, TEST_QEMU_CAPS_PATH)) > 0) {
VIR_FREE(tmp);
if ((rc = VIR_STRDUP(tmp, STRSKIP(ent->d_name, "caps_"))) < 0)
goto cleanup;
tmp = g_strdup(STRSKIP(ent->d_name, "caps_"));
if (rc == 0)
if (!tmp)
continue;
if (!virStringStripSuffix(tmp, fullsuffix))
@ -1051,8 +1041,7 @@ testQemuInfoSetArgs(struct testQemuInfo *info,
bool stripmachinealiases = false;
if (STREQ(capsver, "latest")) {
if (VIR_STRDUP(capsfile, virHashLookup(capslatest, capsarch)) < 0)
goto cleanup;
capsfile = g_strdup(virHashLookup(capslatest, capsarch));
stripmachinealiases = true;
} else if (virAsprintf(&capsfile, "%s/caps_%s.%s.xml",
TEST_QEMU_CAPS_PATH, capsver, capsarch) < 0) {

View File

@ -58,9 +58,7 @@ testCompareXMLtoXMLFiles(const char *xml)
int ret = -1;
virVBoxSnapshotConfMachinePtr machine = NULL;
if (VIR_STRDUP(pathResult,
abs_builddir "/vboxsnapshotxmldata/testResult.vbox") < 0)
return -1;
pathResult = g_strdup(abs_builddir "/vboxsnapshotxmldata/testResult.vbox");
if (virFileMakePath(abs_builddir "/vboxsnapshotxmldata") < 0)
goto cleanup;

View File

@ -409,8 +409,7 @@ testDispose(const void *opaque G_GNUC_UNUSED)
VIR_DISPOSE_N(nums, nnums);
if (VIR_STRDUP(str, "test") < 0)
return -1;
str = g_strdup("test");
VIR_DISPOSE_STRING(str);

View File

@ -992,10 +992,7 @@ initFakeFS(const char *mode,
{
char *fakerootdir;
if (VIR_STRDUP_QUIET(fakerootdir, FAKEROOTDIRTEMPLATE) < 0) {
fprintf(stderr, "Out of memory\n");
abort();
}
fakerootdir = g_strdup(FAKEROOTDIRTEMPLATE);
if (!mkdtemp(fakerootdir)) {
fprintf(stderr, "Cannot create fakerootdir");

View File

@ -71,14 +71,9 @@ testFileCacheObjNew(const char *data)
if (!(obj = virObjectNew(testFileCacheObjClass)))
return NULL;
if (VIR_STRDUP(obj->data, data) < 0)
goto error;
obj->data = g_strdup(data);
return obj;
error:
virObjectUnref(obj);
return NULL;
}

View File

@ -961,19 +961,17 @@ testFirewallQueryHook(const char *const*args,
const char *input G_GNUC_UNUSED,
char **output,
char **error G_GNUC_UNUSED,
int *status,
int *status G_GNUC_UNUSED,
void *opaque G_GNUC_UNUSED)
{
if (STREQ(args[0], IPTABLES_PATH) &&
STREQ(args[1], "-L")) {
if (VIR_STRDUP(*output, TEST_FILTER_TABLE_LIST) < 0)
*status = 127;
*output = g_strdup(TEST_FILTER_TABLE_LIST);
} else if (STREQ(args[0], IPTABLES_PATH) &&
STREQ(args[1], "-t") &&
STREQ(args[2], "nat") &&
STREQ(args[3], "-L")) {
if (VIR_STRDUP(*output, TEST_NAT_TABLE_LIST) < 0)
*status = 127;
*output = g_strdup(TEST_NAT_TABLE_LIST);
}
}

View File

@ -117,8 +117,7 @@ myInit(void)
goto cleanup;
if ((mgr->activeSCSIHostdevs = virSCSIDeviceListNew()) == NULL)
goto cleanup;
if (VIR_STRDUP(mgr->stateDir, TEST_STATE_DIR) < 0)
goto cleanup;
mgr->stateDir = g_strdup(TEST_STATE_DIR);
if (virFileMakePath(mgr->stateDir) < 0)
goto cleanup;
@ -501,10 +500,7 @@ mymain(void)
int ret = 0;
g_autofree char *fakerootdir = NULL;
if (VIR_STRDUP_QUIET(fakerootdir, FAKEROOTDIRTEMPLATE) < 0) {
fprintf(stderr, "Out of memory\n");
abort();
}
fakerootdir = g_strdup(FAKEROOTDIRTEMPLATE);
if (!mkdtemp(fakerootdir)) {
fprintf(stderr, "Cannot create fakerootdir");

View File

@ -228,15 +228,16 @@ static int testMessagePayloadEncode(const void *args G_GNUC_UNUSED)
err.level = VIR_ERR_ERROR;
if (VIR_ALLOC(err.message) < 0 ||
VIR_STRDUP(*err.message, "Hello World") < 0 ||
VIR_ALLOC(err.str1) < 0 ||
VIR_STRDUP(*err.str1, "One") < 0 ||
VIR_ALLOC(err.str2) < 0 ||
VIR_STRDUP(*err.str2, "Two") < 0 ||
VIR_ALLOC(err.str3) < 0 ||
VIR_STRDUP(*err.str3, "Three") < 0)
VIR_ALLOC(err.str3) < 0)
goto cleanup;
*err.message = g_strdup("Hello World");
*err.str1 = g_strdup("One");
*err.str2 = g_strdup("Two");
*err.str3 = g_strdup("Three");
err.int1 = 1;
err.int2 = 2;

View File

@ -289,8 +289,7 @@ getrealpath(char **newpath,
return -1;
}
} else {
if (VIR_STRDUP_QUIET(*newpath, path) < 0)
return -1;
*newpath = g_strdup(path);
}
return 0;
@ -324,12 +323,12 @@ add_fd(int fd, const char *path)
fd, path, cb.fd, cb.path);
}
if (VIR_REALLOC_N_QUIET(callbacks, nCallbacks + 1) < 0 ||
VIR_STRDUP_QUIET(callbacks[nCallbacks].path, path) < 0) {
if (VIR_REALLOC_N_QUIET(callbacks, nCallbacks + 1) < 0) {
errno = ENOMEM;
goto cleanup;
}
callbacks[nCallbacks].path = g_strdup(path);
callbacks[nCallbacks++].fd = fd;
ret = 0;
cleanup:
@ -477,10 +476,11 @@ pci_device_new_from_stub(const struct pciDevice *data)
struct stat sb;
bool configSrcExists = false;
if (!(devid = pci_address_format(&data->addr)) ||
VIR_STRDUP_QUIET(id, devid) < 0)
if (!(devid = pci_address_format(&data->addr)))
ABORT_OOM();
id = g_strdup(devid);
/* Replace ':' with '-' to create the config filename from the
* device ID. The device ID cannot be used directly as filename
* because it contains ':' and Windows does not allow ':' in
@ -724,9 +724,10 @@ pci_driver_new(const char *name, ...)
int vendor, device;
g_autofree char *driverpath = NULL;
if (VIR_ALLOC_QUIET(driver) < 0 ||
VIR_STRDUP_QUIET(driver->name, name) < 0 ||
!(driverpath = pci_driver_get_path(driver, NULL, true)))
if (VIR_ALLOC_QUIET(driver) < 0)
ABORT_OOM();
driver->name = g_strdup(name);
if (!(driverpath = pci_driver_get_path(driver, NULL, true)))
ABORT_OOM();
if (virFileMakePath(driverpath) < 0)

View File

@ -328,10 +328,7 @@ mymain(void)
int ret = 0;
char *fakerootdir;
if (VIR_STRDUP_QUIET(fakerootdir, FAKEROOTDIRTEMPLATE) < 0) {
VIR_TEST_DEBUG("Out of memory");
abort();
}
fakerootdir = g_strdup(FAKEROOTDIRTEMPLATE);
if (!mkdtemp(fakerootdir)) {
VIR_TEST_DEBUG("Cannot create fakerootdir");

View File

@ -222,10 +222,7 @@ mymain(void)
VIR_FREE(virscsi_prefix);
if (VIR_STRDUP(virscsi_prefix, tmpdir) < 0) {
ret = -1;
goto cleanup;
}
virscsi_prefix = g_strdup(tmpdir);
if (virTestRun("test1", test1, NULL) < 0)
ret = -1;

View File

@ -102,8 +102,7 @@ testStorageFileGetMetadata(const char *path,
}
}
if (VIR_STRDUP(def->path, path) < 0)
return NULL;
def->path = g_strdup(path);
if (virStorageFileGetMetadata(def, uid, gid, false) < 0)
return NULL;
@ -480,8 +479,7 @@ testPathCanonicalizeReadlink(const char *path,
for (i = 0; i < G_N_ELEMENTS(testPathCanonicalizeSymlinks); i++) {
if (STREQ(path, testPathCanonicalizeSymlinks[i][0])) {
if (VIR_STRDUP(*linkpath, testPathCanonicalizeSymlinks[i][1]) < 0)
return -1;
*linkpath = g_strdup(testPathCanonicalizeSymlinks[i][1]);
return 0;
}

View File

@ -718,8 +718,7 @@ static int testStripIPv6Brackets(const void *args)
int ret = -1;
char *res = NULL;
if (VIR_STRDUP(res, data->string) < 0)
goto cleanup;
res = g_strdup(data->string);
virStringStripIPv6Brackets(res);
@ -742,8 +741,7 @@ static int testStripControlChars(const void *args)
int ret = -1;
char *res = NULL;
if (VIR_STRDUP(res, data->string) < 0)
goto cleanup;
res = g_strdup(data->string);
virStringStripControlChars(res);
@ -772,8 +770,7 @@ static int testFilterChars(const void *args)
int ret = -1;
char *res = NULL;
if (VIR_STRDUP(res, data->string) < 0)
goto cleanup;
res = g_strdup(data->string);
virStringFilterChars(res, data->valid);

View File

@ -122,8 +122,7 @@ checkPath(const char *path,
} else {
/* Yeah, our worst nightmares just became true. Path does
* not exist. Cut off the last component and retry. */
if (VIR_STRDUP_QUIET(crippledPath, relPath ? relPath : path) < 0)
goto error;
crippledPath = g_strdup(relPath ? relPath : path);
virFileRemoveLastComponent(crippledPath);

View File

@ -56,8 +56,8 @@ static char *get_fake_path(const char *real_path)
if ((p = STRSKIP(real_path, USB_SYSFS)) &&
virAsprintfQuiet(&path, "%s/%s/%s", abs_srcdir, FAKE_USB_SYSFS, p) < 0)
goto error;
else if (!p && VIR_STRDUP_QUIET(path, real_path) < 0)
goto error;
else if (!p)
path = g_strdup(real_path);
return path;

View File

@ -142,8 +142,7 @@ testParseVMXFileName(const char *fileName, void *opaque G_GNUC_UNUSED)
if (STRPREFIX(fileName, "/vmfs/volumes/")) {
/* Found absolute path referencing a file inside a datastore */
if (VIR_STRDUP(copyOfFileName, fileName) < 0)
goto cleanup;
copyOfFileName = g_strdup(fileName);
/* Expected format: '/vmfs/volumes/<datastore>/<path>' */
if ((tmp = STRSKIP(copyOfFileName, "/vmfs/volumes/")) == NULL ||

View File

@ -153,8 +153,7 @@ testFormatVMXFileName(const char *src, void *opaque G_GNUC_UNUSED)
if (STRPREFIX(src, "[")) {
/* Found potential datastore path */
if (VIR_STRDUP(copyOfDatastorePath, src) < 0)
goto cleanup;
copyOfDatastorePath = g_strdup(src);
/* Expected format: '[<datastore>] <path>' where <path> is optional */
if ((tmp = STRSKIP(copyOfDatastorePath, "[")) == NULL || *tmp == ']' ||