---
tests/commandhelper.c | 14 +++++++++++---
tests/commandtest.c | 2 +-
tests/openvzutilstest.c | 6 ++++--
tests/qemumonitortestutils.c | 8 ++++----
tests/qemuxml2argvtest.c | 27 ++++++++++++++++-----------
tests/qemuxmlnstest.c | 4 +++-
tests/securityselinuxhelper.c | 7 +++++--
tests/securityselinuxlabeltest.c | 2 +-
tests/securityselinuxtest.c | 6 ++----
tests/storagebackendsheepdogtest.c | 6 ++----
tests/testutils.c | 4 +++-
tests/testutilsqemu.c | 5 ++++-
tests/vircgrouptest.c | 2 +-
tests/virnetmessagetest.c | 21 +++++++++------------
tests/vmx2xmltest.c | 10 +++++-----
tests/xml2vmxtest.c | 10 +++++-----
16 files changed, 76 insertions(+), 58 deletions(-)
diff --git a/tests/commandhelper.c b/tests/commandhelper.c
index 92f031f..8012424 100644
--- a/tests/commandhelper.c
+++ b/tests/commandhelper.c
@@ -31,6 +31,9 @@
#include "viralloc.h"
#include "virfile.h"
#include "testutils.h"
+#include "virstring.h"
+
+#define VIR_FROM_THIS VIR_FROM_NONE
#ifndef WIN32
@@ -42,9 +45,14 @@ static int envsort(const void *a, const void *b) {
const char *bstr = *bstrptr;
char *aeq = strchr(astr, '=');
char *beq = strchr(bstr, '=');
- char *akey = strndup(astr, aeq - astr);
- char *bkey = strndup(bstr, beq - bstr);
- int ret = strcmp(akey, bkey);
+ char *akey, *bkey;
+ int ret;
+
+ if (VIR_STRNDUP(akey, astr, aeq - astr) < 0 ||
+ VIR_STRNDUP(bkey, bstr, beq - bstr) < 0)
+ ret = 0;
+ else
+ ret = strcmp(akey, bkey);
VIR_FREE(akey);
VIR_FREE(bkey);
return ret;
diff --git a/tests/commandtest.c b/tests/commandtest.c
index 6cb88c5..097e605 100644
--- a/tests/commandtest.c
+++ b/tests/commandtest.c
@@ -685,7 +685,7 @@ static int test17(const void *unused ATTRIBUTE_UNUSED)
goto cleanup;
}
VIR_FREE(outbuf);
- if ((outbuf = strdup("should not be leaked")) == NULL) {
+ if (VIR_STRDUP(outbuf, "should not be leaked") < 0) {
puts("test framework failure");
goto cleanup;
}
diff --git a/tests/openvzutilstest.c b/tests/openvzutilstest.c
index be0c74c..3cfbfb9 100644
--- a/tests/openvzutilstest.c
+++ b/tests/openvzutilstest.c
@@ -13,6 +13,8 @@
# include "openvz/openvz_conf.h"
# include "virstring.h"
+# define VIR_FROM_THIS VIR_FROM_NONE
+
static int
testLocateConfFile(int vpsid ATTRIBUTE_UNUSED, char **conffile,
const char *ext ATTRIBUTE_UNUSED)
@@ -103,8 +105,8 @@ testReadNetworkConf(const void *data ATTRIBUTE_UNUSED)
"</domain>\n";
if (VIR_ALLOC(def) < 0 ||
- !(def->os.type = strdup("exe")) ||
- !(def->os.init = strdup("/sbin/init")))
+ VIR_STRDUP(def->os.type, "exe") < 0 ||
+ VIR_STRDUP(def->os.init, "/sbin/init") < 0)
goto cleanup;
def->virtType = VIR_DOMAIN_VIRT_OPENVZ;
diff --git a/tests/qemumonitortestutils.c b/tests/qemumonitortestutils.c
index c24a37f..2f00cb7 100644
--- a/tests/qemumonitortestutils.c
+++ b/tests/qemumonitortestutils.c
@@ -159,7 +159,7 @@ static int qemuMonitorTestProcessCommandText(qemuMonitorTestPtr test,
char *cmdname;
int ret = -1;
- if (!(cmdname = strdup(cmdstr))) {
+ if (VIR_STRDUP(cmdname, cmdstr) < 0) {
virReportOOMError();
return -1;
}
@@ -407,8 +407,8 @@ qemuMonitorTestAddItem(qemuMonitorTestPtr test,
if (VIR_ALLOC(item) < 0)
goto no_memory;
- if (!(item->command_name = strdup(command_name)) ||
- !(item->response = strdup(response)))
+ if (VIR_STRDUP(item->command_name, command_name) < 0 ||
+ VIR_STRDUP(item->response, response) < 0)
goto no_memory;
virMutexLock(&test->lock);
@@ -467,7 +467,7 @@ qemuMonitorTestPtr qemuMonitorTestNew(bool json, virDomainXMLOptionPtr
xmlopt)
return NULL;
}
- if (!(tmpdir_template = strdup("/tmp/libvirt_XXXXXX")))
+ if (VIR_STRDUP(tmpdir_template, "/tmp/libvirt_XXXXXX") < 0)
goto no_memory;
if (!(test->tmpdir = mkdtemp(tmpdir_template))) {
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 1286273..df53c2e 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -20,9 +20,10 @@
# include "datatypes.h"
# include "cpu/cpu_map.h"
# include "virstring.h"
-
# include "testutilsqemu.h"
+# define VIR_FROM_THIS VIR_FROM_NONE
+
static const char *abs_top_srcdir;
static virQEMUDriver driver;
@@ -32,8 +33,9 @@ fakeSecretGetValue(virSecretPtr obj ATTRIBUTE_UNUSED,
unsigned int fakeflags ATTRIBUTE_UNUSED,
unsigned int internalFlags ATTRIBUTE_UNUSED)
{
- char *secret = strdup("AQCVn5hO6HzFAhAAq0NCv8jtJcIcE+HOBlMQ1A");
- if (!secret) {
+ char *secret;
+
+ if (VIR_STRDUP(secret, "AQCVn5hO6HzFAhAAq0NCv8jtJcIcE+HOBlMQ1A") < 0) {
return NULL;
}
*value_size = strlen(secret);
@@ -129,7 +131,7 @@ static int testCompareXMLToArgvFiles(const char *xml,
if (STREQ(vmdef->os.machine, "pc") &&
STREQ(vmdef->emulator, "/usr/bin/qemu-system-x86_64")) {
VIR_FREE(vmdef->os.machine);
- if (!(vmdef->os.machine = strdup("pc-0.11")))
+ if (VIR_STRDUP(vmdef->os.machine, "pc-0.11") < 0)
goto out;
}
@@ -288,10 +290,10 @@ mymain(void)
VIR_FREE(driver.config->vncListen);
VIR_FREE(driver.config->vncTLSx509certdir);
- if ((driver.config->vncTLSx509certdir = strdup("/etc/pki/libvirt-vnc"))
== NULL)
+ if (VIR_STRDUP(driver.config->vncTLSx509certdir, "/etc/pki/libvirt-vnc")
< 0)
return EXIT_FAILURE;
VIR_FREE(driver.config->spiceTLSx509certdir);
- if ((driver.config->spiceTLSx509certdir =
strdup("/etc/pki/libvirt-spice")) == NULL)
+ if (VIR_STRDUP(driver.config->spiceTLSx509certdir,
"/etc/pki/libvirt-spice") < 0)
return EXIT_FAILURE;
if ((driver.caps = testQemuCapsInit()) == NULL)
@@ -299,16 +301,16 @@ mymain(void)
if (!(driver.xmlopt = virQEMUDriverCreateXMLConf(&driver)))
return EXIT_FAILURE;
VIR_FREE(driver.config->stateDir);
- if ((driver.config->stateDir = strdup("/nowhere")) == NULL)
+ if (VIR_STRDUP(driver.config->stateDir, "/nowhere") < 0)
return EXIT_FAILURE;
VIR_FREE(driver.config->hugetlbfsMount);
- if ((driver.config->hugetlbfsMount = strdup("/dev/hugepages")) == NULL)
+ if (VIR_STRDUP(driver.config->hugetlbfsMount, "/dev/hugepages") < 0)
return EXIT_FAILURE;
VIR_FREE(driver.config->hugepagePath);
- if ((driver.config->hugepagePath =
strdup("/dev/hugepages/libvirt/qemu")) == NULL)
+ if (VIR_STRDUP(driver.config->hugepagePath,
"/dev/hugepages/libvirt/qemu") < 0)
return EXIT_FAILURE;
driver.config->spiceTLS = 1;
- if (!(driver.config->spicePassword = strdup("123456")))
+ if (VIR_STRDUP(driver.config->spicePassword, "123456") < 0)
return EXIT_FAILURE;
if (virAsprintf(&map, "%s/src/cpu/cpu_map.xml", abs_top_srcdir) < 0
||
cpuMapOverride(map) < 0) {
@@ -601,7 +603,9 @@ mymain(void)
driver.config->vncSASL = 1;
VIR_FREE(driver.config->vncSASLdir);
- driver.config->vncSASLdir = strdup("/root/.sasl2");
+ if (VIR_STRDUP(driver.config->vncSASLdir, "/root/.sasl2") < 0)
+ goto cleanup;
+
DO_TEST("graphics-vnc-sasl", QEMU_CAPS_VNC, QEMU_CAPS_VGA);
driver.config->vncTLS = 1;
driver.config->vncTLSx509verify = 1;
@@ -974,6 +978,7 @@ mymain(void)
DO_TEST("pci-autoadd-addr", QEMU_CAPS_DEVICE,
QEMU_CAPS_DEVICE_PCI_BRIDGE);
DO_TEST("pci-autoadd-idx", QEMU_CAPS_DEVICE, QEMU_CAPS_DEVICE_PCI_BRIDGE);
+cleanup:
virObjectUnref(driver.config);
virObjectUnref(driver.caps);
virObjectUnref(driver.xmlopt);
diff --git a/tests/qemuxmlnstest.c b/tests/qemuxmlnstest.c
index cd493e3..42d75dd 100644
--- a/tests/qemuxmlnstest.c
+++ b/tests/qemuxmlnstest.c
@@ -21,6 +21,8 @@
# include "testutilsqemu.h"
# include "virstring.h"
+# define VIR_FROM_THIS VIR_FROM_NONE
+
static const char *abs_top_srcdir;
static virQEMUDriver driver;
@@ -68,7 +70,7 @@ static int testCompareXMLToArgvFiles(const char *xml,
* detects such paths, strips the extra '/' and makes the path absolute.
*/
if (vmdef->emulator && STRPREFIX(vmdef->emulator, "/.")) {
- if (!(emulator = strdup(vmdef->emulator + 1)))
+ if (VIR_STRDUP(emulator, vmdef->emulator + 1) < 0)
goto fail;
VIR_FREE(vmdef->emulator);
vmdef->emulator = NULL;
diff --git a/tests/securityselinuxhelper.c b/tests/securityselinuxhelper.c
index 647b841..1feed1c 100644
--- a/tests/securityselinuxhelper.c
+++ b/tests/securityselinuxhelper.c
@@ -28,6 +28,9 @@
# include <attr/xattr.h>
#endif
+#include "virstring.h"
+
+#define VIR_FROM_THIS VIR_FROM_NONE
/*
* The kernel policy will not allow us to arbitrarily change
@@ -43,7 +46,7 @@ int getcon_raw(security_context_t *context)
errno = EINVAL;
return -1;
}
- if (!(*context = strdup(getenv("FAKE_CONTEXT"))))
+ if (VIR_STRDUP(*context, getenv("FAKE_CONTEXT")) < 0)
return -1;
return 0;
}
@@ -65,7 +68,7 @@ int getpidcon_raw(pid_t pid, security_context_t *context)
errno = EINVAL;
return -1;
}
- if (!(*context = strdup(getenv("FAKE_CONTEXT"))))
+ if (VIR_STRDUP(*context, getenv("FAKE_CONTEXT")) < 0)
return -1;
return 0;
}
diff --git a/tests/securityselinuxlabeltest.c b/tests/securityselinuxlabeltest.c
index e270a76..48f0c5f 100644
--- a/tests/securityselinuxlabeltest.c
+++ b/tests/securityselinuxlabeltest.c
@@ -116,7 +116,7 @@ testSELinuxLoadFileList(const char *testname,
goto cleanup;
}
if (*tmp != '\0' && *tmp != '\n') {
- if (!(context = strdup(tmp))) {
+ if (VIR_STRDUP(context, tmp) < 0) {
VIR_FREE(line);
VIR_FREE(file);
virReportOOMError();
diff --git a/tests/securityselinuxtest.c b/tests/securityselinuxtest.c
index dd4cd11..481bb0d 100644
--- a/tests/securityselinuxtest.c
+++ b/tests/securityselinuxtest.c
@@ -80,12 +80,10 @@ testBuildDomainDef(bool dynamic,
def->seclabels[0] = secdef;
def->seclabels[0]->type = dynamic ? VIR_DOMAIN_SECLABEL_DYNAMIC :
VIR_DOMAIN_SECLABEL_STATIC;
- if (label &&
- !(def->seclabels[0]->label = strdup(label)))
+ if (label && VIR_STRDUP(def->seclabels[0]->label, label) < 0)
goto no_memory;
- if (baselabel &&
- !(def->seclabels[0]->baselabel = strdup(baselabel)))
+ if (baselabel && VIR_STRDUP(def->seclabels[0]->baselabel, baselabel)
< 0)
goto no_memory;
return def;
diff --git a/tests/storagebackendsheepdogtest.c b/tests/storagebackendsheepdogtest.c
index 8800acb..19a6e71 100644
--- a/tests/storagebackendsheepdogtest.c
+++ b/tests/storagebackendsheepdogtest.c
@@ -56,8 +56,7 @@ test_node_info_parser(collie_test test, char *poolxml)
if (!(pool = virStoragePoolDefParseString(poolXmlData)))
goto cleanup;
- output = strdup(test.output);
- if (!output)
+ if (VIR_STRDUP(output, test.output) < 0)
goto cleanup;
if (virStorageBackendSheepdogParseNodeInfo(pool, output) !=
@@ -101,8 +100,7 @@ test_vdi_list_parser(collie_test test, char *poolxml, char *volxml)
if (!(vol = virStorageVolDefParseString(pool, volXmlData)))
goto cleanup;
- output = strdup(test.output);
- if (!output)
+ if (VIR_STRDUP(output, test.output) < 0)
goto cleanup;
if (virStorageBackendSheepdogParseVdiList(vol, output) !=
diff --git a/tests/testutils.c b/tests/testutils.c
index b0806de..e2d8432 100644
--- a/tests/testutils.c
+++ b/tests/testutils.c
@@ -512,7 +512,9 @@ virtTestLogContentAndReset(void)
if (virBufferError(&testLog.buf))
return NULL;
ret = virBufferContentAndReset(&testLog.buf);
- return ret ? ret : strdup("");
+ if (!ret && VIR_STRDUP(ret, "") < 0)
+ virReportOOMError();
+ return ret;
}
#if TEST_OOM_TRACE
diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c
index fba17a3..68bfb49 100644
--- a/tests/testutilsqemu.c
+++ b/tests/testutilsqemu.c
@@ -8,6 +8,9 @@
# include "cpu_conf.h"
# include "qemu/qemu_driver.h"
# include "qemu/qemu_domain.h"
+# include "virstring.h"
+
+# define VIR_FROM_THIS VIR_FROM_NONE
static virCapsGuestMachinePtr *testQemuAllocMachines(int *nmachines)
{
@@ -38,7 +41,7 @@ static virCapsGuestMachinePtr *testQemuAllocNewerMachines(int
*nmachines)
"pc-0.11", "pc", "pc-0.10", "isapc"
};
- if ((canonical = strdup(x86_machines[0])) == NULL)
+ if (VIR_STRDUP(canonical, x86_machines[0]) < 0)
return NULL;
machines = virCapabilitiesAllocMachines(x86_machines,
diff --git a/tests/vircgrouptest.c b/tests/vircgrouptest.c
index 4777fae..27f24cb 100644
--- a/tests/vircgrouptest.c
+++ b/tests/vircgrouptest.c
@@ -501,7 +501,7 @@ mymain(void)
int ret = 0;
char *fakesysfsdir;
- if (!(fakesysfsdir = strdup(FAKESYSFSDIRTEMPLATE))) {
+ if (VIR_STRDUP(fakesysfsdir, FAKESYSFSDIRTEMPLATE) < 0) {
fprintf(stderr, "Out of memory\n");
abort();
}
diff --git a/tests/virnetmessagetest.c b/tests/virnetmessagetest.c
index 96defe4..7e81ef0 100644
--- a/tests/virnetmessagetest.c
+++ b/tests/virnetmessagetest.c
@@ -27,7 +27,7 @@
#include "virerror.h"
#include "viralloc.h"
#include "virlog.h"
-
+#include "virstring.h"
#include "rpc/virnetmessage.h"
#define VIR_FROM_THIS VIR_FROM_RPC
@@ -236,18 +236,15 @@ static int testMessagePayloadEncode(const void *args
ATTRIBUTE_UNUSED)
err.domain = VIR_FROM_RPC;
err.level = VIR_ERR_ERROR;
- if (VIR_ALLOC(err.message) < 0)
- goto cleanup;
- *err.message = strdup("Hello World");
- if (VIR_ALLOC(err.str1) < 0)
- goto cleanup;
- *err.str1 = strdup("One");
- if (VIR_ALLOC(err.str2) < 0)
- goto cleanup;
- *err.str2 = strdup("Two");
- if (VIR_ALLOC(err.str3) < 0)
+ 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)
goto cleanup;
- *err.str3 = strdup("Three");
err.int1 = 1;
err.int2 = 2;
diff --git a/tests/vmx2xmltest.c b/tests/vmx2xmltest.c
index bd7cbc6..db41926 100644
--- a/tests/vmx2xmltest.c
+++ b/tests/vmx2xmltest.c
@@ -13,6 +13,8 @@
# include "vmx/vmx.h"
# include "virstring.h"
+# define VIR_FROM_THIS VIR_FROM_NONE
+
static virCapsPtr caps;
static virDomainXMLOptionPtr xmlopt;
static virVMXContext ctx;
@@ -159,11 +161,8 @@ testParseVMXFileName(const char *fileName, void *opaque
ATTRIBUTE_UNUSED)
if (STRPREFIX(fileName, "/vmfs/volumes/")) {
/* Found absolute path referencing a file inside a datastore */
- copyOfFileName = strdup(fileName);
-
- if (copyOfFileName == NULL) {
+ if (VIR_STRDUP(copyOfFileName, fileName) < 0)
goto cleanup;
- }
/* Expected format: '/vmfs/volumes/<datastore>/<path>' */
if ((tmp = STRSKIP(copyOfFileName, "/vmfs/volumes/")) == NULL ||
@@ -177,7 +176,8 @@ testParseVMXFileName(const char *fileName, void *opaque
ATTRIBUTE_UNUSED)
goto cleanup;
} else if (STRPREFIX(fileName, "/")) {
/* Found absolute path referencing a file outside a datastore */
- src = strdup(fileName);
+ if (VIR_STRDUP(src, fileName) < 0)
+ goto cleanup;
} else if (strchr(fileName, '/') != NULL) {
/* Found relative path, this is not supported */
src = NULL;
diff --git a/tests/xml2vmxtest.c b/tests/xml2vmxtest.c
index 38b5a4d..46180fd 100644
--- a/tests/xml2vmxtest.c
+++ b/tests/xml2vmxtest.c
@@ -13,6 +13,8 @@
# include "vmx/vmx.h"
# include "virstring.h"
+# define VIR_FROM_THIS VIR_FROM_NONE
+
static virCapsPtr caps;
static virVMXContext ctx;
static virDomainXMLOptionPtr xmlopt;
@@ -169,11 +171,8 @@ testFormatVMXFileName(const char *src, void *opaque
ATTRIBUTE_UNUSED)
if (STRPREFIX(src, "[")) {
/* Found potential datastore path */
- copyOfDatastorePath = strdup(src);
-
- if (copyOfDatastorePath == NULL) {
+ if (VIR_STRDUP(copyOfDatastorePath, src) < 0)
goto cleanup;
- }
/* Expected format: '[<datastore>] <path>' where <path>
is optional */
if ((tmp = STRSKIP(copyOfDatastorePath, "[")) == NULL || *tmp ==
']' ||
@@ -194,7 +193,8 @@ testFormatVMXFileName(const char *src, void *opaque ATTRIBUTE_UNUSED)
goto cleanup;
} else if (STRPREFIX(src, "/")) {
/* Found absolute path */
- absolutePath = strdup(src);
+ if (VIR_STRDUP(absolutePath, src) < 0)
+ goto cleanup;
} else {
/* Found relative path, this is not supported */
goto cleanup;
--
1.8.1.5