virQEMUDriverConfig *cfg)
{
int ret = -1;
- char *path = NULL;
+ g_autofree char *path = NULL;
g_autoptr(virQEMUCaps) qemuCaps = NULL;
virDomainCapsLoader *loader = &domCaps->os.loader;
virDomainVirtType virtType;
ret = 0;
cleanup:
- VIR_FREE(path);
return ret;
}
#endif /* WITH_QEMU */
static int
fillBhyveCaps(virDomainCaps *domCaps, unsigned int *bhyve_caps)
{
- virDomainCapsStringValues *firmwares = NULL;
+ g_autofree virDomainCapsStringValues *firmwares = NULL;
int ret = -1;
firmwares = g_new0(virDomainCapsStringValues, 1);
ret = 0;
cleanup:
- VIR_FREE(firmwares);
return ret;
}
#endif /* WITH_BHYVE */
{
const struct testData *data = opaque;
g_autoptr(virDomainCaps) domCaps = NULL;
- char *path = NULL;
- char *domCapsXML = NULL;
+ g_autofree char *path = NULL;
+ g_autofree char *domCapsXML = NULL;
int ret = -1;
path = g_strdup_printf("%s/domaincapsdata/%s.xml", abs_srcdir, data->name);
ret = 0;
cleanup:
- VIR_FREE(domCapsXML);
- VIR_FREE(path);
return ret;
}
#define DO_TEST_BHYVE(Name, Emulator, BhyveCaps, Type) \
do { \
- char *name = NULL; \
+ g_autofree char *name = NULL; \
name = g_strdup_printf("bhyve_%s.x86_64", Name); \
struct testData data = { \
.name = name, \
}; \
if (virTestRun(name, test_virDomainCapsFormat, &data) < 0) \
ret = -1; \
- VIR_FREE(name); \
} while (0)
DO_TEST("empty", "/bin/emulatorbin", "my-machine-type",
{
int ret = -1;
virDomainDef *def = NULL;
- char *filename = NULL;
+ g_autofree char *filename = NULL;
const struct testGetFilesystemData *data = opaque;
virDomainFSDef *fsdef;
cleanup:
virDomainDefFree(def);
- VIR_FREE(filename);
return ret;
}
testEventReport(const char *name, bool failed, const char *msg, ...)
{
va_list vargs;
- char *str = NULL;
+ g_autofree char *str = NULL;
struct testEventResultData data;
va_start(vargs, msg);
ignore_value(virTestRun(name, testEventResultCallback, &data));
va_end(vargs);
- VIR_FREE(str);
}
static void
const char *expect_fabric_wwn = "2001000dec9877c1";
const char *expect_max_vports = "127";
const char *expect_vports = "0";
- char *wwnn = NULL;
- char *wwpn = NULL;
- char *fabric_wwn = NULL;
- char *max_vports = NULL;
- char *vports = NULL;
+ g_autofree char *wwnn = NULL;
+ g_autofree char *wwpn = NULL;
+ g_autofree char *fabric_wwn = NULL;
+ g_autofree char *max_vports = NULL;
+ g_autofree char *vports = NULL;
int ret = -1;
if (!(wwnn = virVHBAGetConfig(TEST_FC_HOST_PREFIX, TEST_FC_HOST_NUM,
ret = 0;
cleanup:
- VIR_FREE(wwnn);
- VIR_FREE(wwpn);
- VIR_FREE(fabric_wwn);
- VIR_FREE(max_vports);
- VIR_FREE(vports);
return ret;
}
test4(const void *data G_GNUC_UNUSED)
{
const char *expect_hostname = "host5";
- char *hostname = NULL;
+ g_autofree char *hostname = NULL;
int ret = -1;
if (!(hostname = virVHBAGetHostByWWN(TEST_FC_HOST_PREFIX,
ret = 0;
cleanup:
- VIR_FREE(hostname);
return ret;
}
test5(const void *data G_GNUC_UNUSED)
{
const char *expect_hostname = "host5";
- char *hostname = NULL;
+ g_autofree char *hostname = NULL;
int ret = -1;
if (!(hostname = virVHBAFindVportHost(TEST_FC_HOST_PREFIX)))
ret = 0;
cleanup:
- VIR_FREE(hostname);
return ret;
}
{
const char *expect_wwnn = "2002001b32a9da4e";
const char *expect_wwpn = "2102001b32a9da4e";
- char *wwnn = NULL;
- char *wwpn = NULL;
- char *fabric_wwn = NULL;
+ g_autofree char *wwnn = NULL;
+ g_autofree char *wwpn = NULL;
+ g_autofree char *fabric_wwn = NULL;
int ret = -1;
if (!(wwnn = virVHBAGetConfig(TEST_FC_HOST_PREFIX, TEST_FC_HOST_NUM_NO_FAB,
ret = 0;
cleanup:
- VIR_FREE(wwnn);
- VIR_FREE(wwpn);
- VIR_FREE(fabric_wwn);
return ret;
}
static int testFDStreamReadCommon(const char *scratchdir, bool blocking)
{
int fd = -1;
- char *file = NULL;
+ g_autofree char *file = NULL;
int ret = -1;
- char *pattern = NULL;
- char *buf = NULL;
+ g_autofree char *pattern = NULL;
+ g_autofree char *buf = NULL;
virStreamPtr st = NULL;
size_t i;
virConnectPtr conn = NULL;
unlink(file);
if (conn)
virConnectClose(conn);
- VIR_FREE(file);
- VIR_FREE(pattern);
- VIR_FREE(buf);
return ret;
}
static int testFDStreamWriteCommon(const char *scratchdir, bool blocking)
{
int fd = -1;
- char *file = NULL;
+ g_autofree char *file = NULL;
int ret = -1;
- char *pattern = NULL;
- char *buf = NULL;
+ g_autofree char *pattern = NULL;
+ g_autofree char *buf = NULL;
virStreamPtr st = NULL;
size_t i;
virConnectPtr conn = NULL;
unlink(file);
if (conn)
virConnectClose(conn);
- VIR_FREE(file);
- VIR_FREE(pattern);
- VIR_FREE(buf);
return ret;
}
testCompareXMLToXMLHelper(const void *data)
{
const struct testInfo *info = data;
- char *xml_in = NULL;
- char *xml_out = NULL;
+ g_autofree char *xml_in = NULL;
+ g_autofree char *xml_out = NULL;
int ret = -1;
xml_in = g_strdup_printf("%s/genericxml2xmlindata/%s.xml",
info->different ? xml_out : xml_in,
info->active_only, 0,
info->expectResult);
- VIR_FREE(xml_in);
- VIR_FREE(xml_out);
return ret;
}
static int
testCompareXMLToXMLFiles(const char *xml)
{
- char *xmlData = NULL;
- char *actual = NULL;
+ g_autofree char *xmlData = NULL;
+ g_autofree char *actual = NULL;
int ret = -1;
virInterfaceDef *dev = NULL;
ret = 0;
fail:
- VIR_FREE(xmlData);
- VIR_FREE(actual);
virInterfaceDefFree(dev);
return ret;
}
testCompareXMLToXMLHelper(const void *data)
{
int result = -1;
- char *xml = NULL;
+ g_autofree char *xml = NULL;
xml = g_strdup_printf("%s/interfaceschemadata/%s.xml", abs_srcdir,
(const char *)data);
result = testCompareXMLToXMLFiles(xml);
- VIR_FREE(xml);
return result;
}
bool expectError)
{
int ret = -1;
- char *config = NULL;
- char *actualxml = NULL;
+ g_autofree char *config = NULL;
+ g_autofree char *actualxml = NULL;
virDomainDef *vmdef = NULL;
if (virTestLoadFile(configfile, &config) < 0)
ret = 0;
fail:
- VIR_FREE(actualxml);
- VIR_FREE(config);
virDomainDefFree(vmdef);
return ret;
}
{
int result = -1;
const struct testInfo *info = data;
- char *xml = NULL;
- char *config = NULL;
+ g_autofree char *xml = NULL;
+ g_autofree char *config = NULL;
xml = g_strdup_printf("%s/lxcconf2xmldata/lxcconf2xml-%s.xml",
abs_srcdir, info->name);
result = testCompareXMLToConfigFiles(xml, config, info->expectError);
- VIR_FREE(xml);
- VIR_FREE(config);
return result;
}
{
int result = -1;
const struct testInfo *info = data;
- char *xml = NULL;
- char *config = NULL;
+ g_autofree char *xml = NULL;
+ g_autofree char *config = NULL;
xml = g_strdup_printf("%s/lxcconf2xmldata/lxcconf2xml-%s.xml",
abs_srcdir, info->name);
result = testCompareXMLToConfigFiles(xml, config, info->expectError);
- VIR_FREE(xml);
- VIR_FREE(config);
return result;
}
testCompareXMLToXMLHelper(const void *data)
{
const struct testInfo *info = data;
- char *xml_in = NULL;
- char *xml_out = NULL;
+ g_autofree char *xml_in = NULL;
+ g_autofree char *xml_out = NULL;
int ret = -1;
xml_in = g_strdup_printf("%s/lxcxml2xmldata/lxc-%s.xml",
info->active_only,
info->parse_flags,
TEST_COMPARE_DOM_XML2XML_RESULT_SUCCESS);
- VIR_FREE(xml_in);
- VIR_FREE(xml_out);
return ret;
}
const char *uri)
{
bool ret = false;
- char *metadataXML = NULL;
- char *metadataAPI = NULL;
+ g_autofree char *metadataXML = NULL;
+ g_autofree char *metadataAPI = NULL;
if (!expectAPI) {
if ((metadataAPI = virDomainGetMetadata(dom,
ret = true;
cleanup:
- VIR_FREE(metadataXML);
- VIR_FREE(metadataAPI);
return ret;
}
testTextMetadata(const void *data)
{
const struct metadataTest *test = data;
- char *actual = NULL;
+ g_autofree char *actual = NULL;
int ret = -1;
if (virDomainSetMetadata(test->dom, test->type, test->data, NULL, NULL, 0) < 0) {
ret = 0;
cleanup:
- VIR_FREE(actual);
return ret;
}
static int
testCompareXMLToXMLFiles(const char *xml, const char *outfile)
{
- char *xmlData = NULL;
- char *actual = NULL;
+ g_autofree char *xmlData = NULL;
+ g_autofree char *actual = NULL;
int ret = -1;
virNodeDeviceDef *dev = NULL;
virNodeDevCapsDef *caps;
ret = 0;
fail:
- VIR_FREE(xmlData);
- VIR_FREE(actual);
virNodeDeviceDefFree(dev);
return ret;
}
testCompareXMLToXMLHelper(const void *data)
{
int result = -1;
- char *xml = NULL;
+ g_autofree char *xml = NULL;
g_autofree char *outfile = NULL;
xml = g_strdup_printf("%s/nodedevschemadata/%s.xml", abs_srcdir,
result = testCompareXMLToXMLFiles(xml, outfile);
- VIR_FREE(xml);
return result;
}
i = 0;
while (*addrList) {
virSocketAddr sa;
- char *ipAddr;
+ g_autofree char *ipAddr = NULL;
void *address = *addrList;
memset(&sa, 0, sizeof(sa));
virReportError(VIR_ERR_INTERNAL_ERROR,
"Unexpected address %s, expecting %s",
ipAddr, NULLSTR(data->ipAddr[i]));
- VIR_FREE(ipAddr);
return -1;
}
- VIR_FREE(ipAddr);
addrList++;
i++;
{
int result = -1;
size_t i;
- char *conf = NULL;
- char *value = NULL;
+ g_autofree char *conf = NULL;
+ g_autofree char *value = NULL;
conf = g_strdup_printf("%s/openvzutilstest.conf", abs_srcdir);
result = 0;
cleanup:
- VIR_FREE(conf);
- VIR_FREE(value);
return result;
}
{
int result = -1;
virDomainDef *def = NULL;
- char *actual = NULL;
+ g_autofree char *actual = NULL;
const char *expected =
"<domain type='openvz'>\n"
" <uuid>00000000-0000-0000-0000-000000000000</uuid>\n"
cleanup:
virObjectUnref(driver.xmlopt);
virObjectUnref(driver.caps);
- VIR_FREE(actual);
virDomainDefFree(def);
return result;
create_scsihost(const char *fakesysfsdir, const char *devicepath,
const char *unique_id, const char *hostname)
{
- char *unique_id_path = NULL;
- char *link_path = NULL;
+ g_autofree char *unique_id_path = NULL;
+ g_autofree char *link_path = NULL;
char *spot;
int ret = -1;
int fd = -1;
cleanup:
VIR_FORCE_CLOSE(fd);
- VIR_FREE(unique_id_path);
- VIR_FREE(link_path);
return ret;
}
mymain(void)
{
int ret = -1;
- char *fakerootdir = NULL;
- char *fakesysfsdir = NULL;
+ g_autofree char *fakerootdir = NULL;
+ g_autofree char *fakesysfsdir = NULL;
fakerootdir = g_strdup(FAKEROOTDIRTEMPLATE);
cleanup:
if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL)
virFileDeleteTree(fakerootdir);
- VIR_FREE(fakerootdir);
- VIR_FREE(fakesysfsdir);
VIR_FREE(scsihost_class_path);
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}
testCompareXMLToXMLHelper(const void *data)
{
int result = -1;
- char *inxml = NULL;
- char *outxml = NULL;
+ g_autofree char *inxml = NULL;
+ g_autofree char *outxml = NULL;
const struct testInfo *info = data;
inxml = g_strdup_printf("%s/secretxml2xmlin/%s.xml", abs_srcdir, info->name);
result = testCompareXMLToXMLFiles(inxml, outxml);
- VIR_FREE(inxml);
- VIR_FREE(outxml);
-
return result;
}
int ret = -1;
ssize_t len;
const char *con_value = "system_u:object_r:svirt_image_t:s0:c41,c264";
- char *path = NULL;
+ g_autofree char *path = NULL;
path = g_strdup_printf("%s/securityselinuxlabeldata/testxattr", abs_builddir);
if (g_mkdir_with_parents(abs_builddir "/securityselinuxlabeldata", 0777) < 0 ||
cleanup:
unlink(path);
rmdir(abs_builddir "/securityselinuxlabeldata");
- VIR_FREE(path);
return ret;
}
size_t *nfiles)
{
int ret = -1;
- char *path = NULL;
+ g_autofree char *path = NULL;
FILE *fp = NULL;
- char *line = NULL;
+ g_autofree char *line = NULL;
*files = NULL;
*nfiles = 0;
cleanup:
VIR_FORCE_FCLOSE(fp);
- VIR_FREE(path);
- VIR_FREE(line);
return ret;
}
static int testFormat(virSocketAddr *addr, const char *addrstr, bool pass)
{
- char *newaddrstr;
+ g_autofree char *newaddrstr = NULL;
newaddrstr = virSocketAddrFormat(addr);
if (!newaddrstr)
if (STRNEQ(newaddrstr, addrstr)) {
virTestDifference(stderr, addrstr, newaddrstr);
- VIR_FREE(newaddrstr);
return pass ? -1 : 0;
} else {
- VIR_FREE(newaddrstr);
return pass ? 0 : -1;
}
}
if (virTestGetDebug()) {
- char *caps_str;
+ g_autofree char *caps_str = NULL;
caps_str = virCapabilitiesFormatXML(caps);
if (!caps_str)
goto error;
VIR_TEST_DEBUG("LXC driver capabilities:\n%s", caps_str);
-
- VIR_FREE(caps_str);
}
return caps;
static int
testCompareXMLtoXMLFiles(const char *xml)
{
- char *xmlData = NULL;
- char *actual = NULL;
- char *pathResult = NULL;
+ g_autofree char *xmlData = NULL;
+ g_autofree char *actual = NULL;
+ g_autofree char *pathResult = NULL;
int ret = -1;
virVBoxSnapshotConfMachine *machine = NULL;
cleanup:
unlink(pathResult);
rmdir(abs_builddir "/vboxsnapshotxmldata");
- VIR_FREE(xmlData);
- VIR_FREE(actual);
virVBoxSnapshotConfMachineFree(machine);
- VIR_FREE(pathResult);
return ret;
}
testCompareXMLToXMLHelper(const void *data)
{
int result = -1;
- char *xml = NULL;
+ g_autofree char *xml = NULL;
xml = g_strdup_printf("%s/vboxsnapshotxmldata/%s.vbox", abs_srcdir,
(const char *)data);
result = testCompareXMLtoXMLFiles(xml);
- VIR_FREE(xml);
return result;
}
{
const struct testInfo *info = data;
int ret = -1;
- char *path = NULL;
- char *databuf = NULL;
+ g_autofree char *path = NULL;
+ g_autofree char *databuf = NULL;
unsigned long version;
int vmware_type;
ret = 0;
cleanup:
- VIR_FREE(path);
- VIR_FREE(databuf);
return ret;
}
testUnicode(const void *opaque G_GNUC_UNUSED)
{
int ret = 0;
- char *act = NULL;
+ g_autofree char *act = NULL;
const char *exp =
" Id 名稱 государство\n"
ret = -1;
cleanup:
- VIR_FREE(act);
vshTableFree(table);
return ret;
}
testUnicodeArabic(const void *opaque G_GNUC_UNUSED)
{
int ret = 0;
- char *act = NULL;
+ g_autofree char *act = NULL;
const char *exp =
" ﻡﺍ ﻢﻣﺍ ﻕﺎﺌﻣﺓ ﺓ ﺎﻠﺼﻋ ﺍﻸﺜﻧﺎﻧ\n"
ret = -1;
cleanup:
- VIR_FREE(act);
vshTableFree(table);
return ret;
}
"--------------------------\n"
" 1\u200B fedora28 run\u200Bning\n"
" 2 rhel7.5 running\n";
- char *act = NULL;
+ g_autofree char *act = NULL;
wchar_t wc;
/* If this char is not classed as printable, the actual
ret = -1;
cleanup:
- VIR_FREE(act);
vshTableFree(table);
return ret;
}
"--------------------------\n"
" 1 fědora28 running\n"
" 2 rhel running\n";
- char *act = NULL;
+ g_autofree char *act = NULL;
table = vshTableNew("Id", "Náme", "Ⓢtatus", NULL);
if (!table)
ret = -1;
cleanup:
- VIR_FREE(act);
vshTableFree(table);
return ret;
}
"----------------------------------\n"
" 1 f\\x07edora28 running\n"
" 2 rhel7.5 running\n";
- char *act = NULL;
+ g_autofree char *act = NULL;
table = vshTableNew("I\td", "Name", "Status", NULL);
if (!table)
ret = -1;
cleanup:
- VIR_FREE(act);
vshTableFree(table);
return ret;
}
" 2\n"
" 3\n"
" 4\n";
- char *act1 = NULL;
- char *act2 = NULL;
- char *act3 = NULL;
+ g_autofree char *act1 = NULL;
+ g_autofree char *act2 = NULL;
+ g_autofree char *act3 = NULL;
table1 = vshTableNew("Id", "Name", "Status", NULL);
if (!table1)
ret = -1;
cleanup:
- VIR_FREE(act1);
- VIR_FREE(act2);
- VIR_FREE(act3);
vshTableFree(table1);
vshTableFree(table2);
vshTableFree(table3);