tests: use g_autofree

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
This commit is contained in:
Ján Tomko 2021-09-04 22:37:44 +02:00
parent 526551ac0a
commit 296f7173ed
21 changed files with 71 additions and 146 deletions

View File

@ -74,7 +74,7 @@ fillQemuCaps(virDomainCaps *domCaps,
virQEMUDriverConfig *cfg) virQEMUDriverConfig *cfg)
{ {
int ret = -1; int ret = -1;
char *path = NULL; g_autofree char *path = NULL;
g_autoptr(virQEMUCaps) qemuCaps = NULL; g_autoptr(virQEMUCaps) qemuCaps = NULL;
virDomainCapsLoader *loader = &domCaps->os.loader; virDomainCapsLoader *loader = &domCaps->os.loader;
virDomainVirtType virtType; virDomainVirtType virtType;
@ -127,7 +127,6 @@ fillQemuCaps(virDomainCaps *domCaps,
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(path);
return ret; return ret;
} }
#endif /* WITH_QEMU */ #endif /* WITH_QEMU */
@ -167,7 +166,7 @@ fillXenCaps(virDomainCaps *domCaps)
static int static int
fillBhyveCaps(virDomainCaps *domCaps, unsigned int *bhyve_caps) fillBhyveCaps(virDomainCaps *domCaps, unsigned int *bhyve_caps)
{ {
virDomainCapsStringValues *firmwares = NULL; g_autofree virDomainCapsStringValues *firmwares = NULL;
int ret = -1; int ret = -1;
firmwares = g_new0(virDomainCapsStringValues, 1); firmwares = g_new0(virDomainCapsStringValues, 1);
@ -180,7 +179,6 @@ fillBhyveCaps(virDomainCaps *domCaps, unsigned int *bhyve_caps)
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(firmwares);
return ret; return ret;
} }
#endif /* WITH_BHYVE */ #endif /* WITH_BHYVE */
@ -208,8 +206,8 @@ test_virDomainCapsFormat(const void *opaque)
{ {
const struct testData *data = opaque; const struct testData *data = opaque;
g_autoptr(virDomainCaps) domCaps = NULL; g_autoptr(virDomainCaps) domCaps = NULL;
char *path = NULL; g_autofree char *path = NULL;
char *domCapsXML = NULL; g_autofree char *domCapsXML = NULL;
int ret = -1; int ret = -1;
path = g_strdup_printf("%s/domaincapsdata/%s.xml", abs_srcdir, data->name); path = g_strdup_printf("%s/domaincapsdata/%s.xml", abs_srcdir, data->name);
@ -253,8 +251,6 @@ test_virDomainCapsFormat(const void *opaque)
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(domCapsXML);
VIR_FREE(path);
return ret; return ret;
} }
@ -400,7 +396,7 @@ mymain(void)
#define DO_TEST_BHYVE(Name, Emulator, BhyveCaps, Type) \ #define DO_TEST_BHYVE(Name, Emulator, BhyveCaps, Type) \
do { \ do { \
char *name = NULL; \ g_autofree char *name = NULL; \
name = g_strdup_printf("bhyve_%s.x86_64", Name); \ name = g_strdup_printf("bhyve_%s.x86_64", Name); \
struct testData data = { \ struct testData data = { \
.name = name, \ .name = name, \
@ -412,7 +408,6 @@ mymain(void)
}; \ }; \
if (virTestRun(name, test_virDomainCapsFormat, &data) < 0) \ if (virTestRun(name, test_virDomainCapsFormat, &data) < 0) \
ret = -1; \ ret = -1; \
VIR_FREE(name); \
} while (0) } while (0)
DO_TEST("empty", "/bin/emulatorbin", "my-machine-type", DO_TEST("empty", "/bin/emulatorbin", "my-machine-type",

View File

@ -42,7 +42,7 @@ static int testGetFilesystem(const void *opaque)
{ {
int ret = -1; int ret = -1;
virDomainDef *def = NULL; virDomainDef *def = NULL;
char *filename = NULL; g_autofree char *filename = NULL;
const struct testGetFilesystemData *data = opaque; const struct testGetFilesystemData *data = opaque;
virDomainFSDef *fsdef; virDomainFSDef *fsdef;
@ -72,7 +72,6 @@ static int testGetFilesystem(const void *opaque)
cleanup: cleanup:
virDomainDefFree(def); virDomainDefFree(def);
VIR_FREE(filename);
return ret; return ret;
} }

View File

@ -89,7 +89,7 @@ G_GNUC_PRINTF(3, 4)
testEventReport(const char *name, bool failed, const char *msg, ...) testEventReport(const char *name, bool failed, const char *msg, ...)
{ {
va_list vargs; va_list vargs;
char *str = NULL; g_autofree char *str = NULL;
struct testEventResultData data; struct testEventResultData data;
va_start(vargs, msg); va_start(vargs, msg);
@ -102,7 +102,6 @@ testEventReport(const char *name, bool failed, const char *msg, ...)
ignore_value(virTestRun(name, testEventResultCallback, &data)); ignore_value(virTestRun(name, testEventResultCallback, &data));
va_end(vargs); va_end(vargs);
VIR_FREE(str);
} }
static void static void

View File

@ -118,11 +118,11 @@ test3(const void *data G_GNUC_UNUSED)
const char *expect_fabric_wwn = "2001000dec9877c1"; const char *expect_fabric_wwn = "2001000dec9877c1";
const char *expect_max_vports = "127"; const char *expect_max_vports = "127";
const char *expect_vports = "0"; const char *expect_vports = "0";
char *wwnn = NULL; g_autofree char *wwnn = NULL;
char *wwpn = NULL; g_autofree char *wwpn = NULL;
char *fabric_wwn = NULL; g_autofree char *fabric_wwn = NULL;
char *max_vports = NULL; g_autofree char *max_vports = NULL;
char *vports = NULL; g_autofree char *vports = NULL;
int ret = -1; int ret = -1;
if (!(wwnn = virVHBAGetConfig(TEST_FC_HOST_PREFIX, TEST_FC_HOST_NUM, if (!(wwnn = virVHBAGetConfig(TEST_FC_HOST_PREFIX, TEST_FC_HOST_NUM,
@ -155,11 +155,6 @@ test3(const void *data G_GNUC_UNUSED)
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(wwnn);
VIR_FREE(wwpn);
VIR_FREE(fabric_wwn);
VIR_FREE(max_vports);
VIR_FREE(vports);
return ret; return ret;
} }
@ -168,7 +163,7 @@ static int
test4(const void *data G_GNUC_UNUSED) test4(const void *data G_GNUC_UNUSED)
{ {
const char *expect_hostname = "host5"; const char *expect_hostname = "host5";
char *hostname = NULL; g_autofree char *hostname = NULL;
int ret = -1; int ret = -1;
if (!(hostname = virVHBAGetHostByWWN(TEST_FC_HOST_PREFIX, if (!(hostname = virVHBAGetHostByWWN(TEST_FC_HOST_PREFIX,
@ -181,7 +176,6 @@ test4(const void *data G_GNUC_UNUSED)
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(hostname);
return ret; return ret;
} }
@ -193,7 +187,7 @@ static int
test5(const void *data G_GNUC_UNUSED) test5(const void *data G_GNUC_UNUSED)
{ {
const char *expect_hostname = "host5"; const char *expect_hostname = "host5";
char *hostname = NULL; g_autofree char *hostname = NULL;
int ret = -1; int ret = -1;
if (!(hostname = virVHBAFindVportHost(TEST_FC_HOST_PREFIX))) if (!(hostname = virVHBAFindVportHost(TEST_FC_HOST_PREFIX)))
@ -204,7 +198,6 @@ test5(const void *data G_GNUC_UNUSED)
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(hostname);
return ret; return ret;
} }
@ -214,9 +207,9 @@ test6(const void *data G_GNUC_UNUSED)
{ {
const char *expect_wwnn = "2002001b32a9da4e"; const char *expect_wwnn = "2002001b32a9da4e";
const char *expect_wwpn = "2102001b32a9da4e"; const char *expect_wwpn = "2102001b32a9da4e";
char *wwnn = NULL; g_autofree char *wwnn = NULL;
char *wwpn = NULL; g_autofree char *wwpn = NULL;
char *fabric_wwn = NULL; g_autofree char *fabric_wwn = NULL;
int ret = -1; int ret = -1;
if (!(wwnn = virVHBAGetConfig(TEST_FC_HOST_PREFIX, TEST_FC_HOST_NUM_NO_FAB, if (!(wwnn = virVHBAGetConfig(TEST_FC_HOST_PREFIX, TEST_FC_HOST_NUM_NO_FAB,
@ -238,9 +231,6 @@ test6(const void *data G_GNUC_UNUSED)
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(wwnn);
VIR_FREE(wwpn);
VIR_FREE(fabric_wwn);
return ret; return ret;
} }

View File

@ -39,10 +39,10 @@ VIR_LOG_INIT("tests.fdstreamtest");
static int testFDStreamReadCommon(const char *scratchdir, bool blocking) static int testFDStreamReadCommon(const char *scratchdir, bool blocking)
{ {
int fd = -1; int fd = -1;
char *file = NULL; g_autofree char *file = NULL;
int ret = -1; int ret = -1;
char *pattern = NULL; g_autofree char *pattern = NULL;
char *buf = NULL; g_autofree char *buf = NULL;
virStreamPtr st = NULL; virStreamPtr st = NULL;
size_t i; size_t i;
virConnectPtr conn = NULL; virConnectPtr conn = NULL;
@ -149,9 +149,6 @@ static int testFDStreamReadCommon(const char *scratchdir, bool blocking)
unlink(file); unlink(file);
if (conn) if (conn)
virConnectClose(conn); virConnectClose(conn);
VIR_FREE(file);
VIR_FREE(pattern);
VIR_FREE(buf);
return ret; return ret;
} }
@ -169,10 +166,10 @@ static int testFDStreamReadNonblock(const void *data)
static int testFDStreamWriteCommon(const char *scratchdir, bool blocking) static int testFDStreamWriteCommon(const char *scratchdir, bool blocking)
{ {
int fd = -1; int fd = -1;
char *file = NULL; g_autofree char *file = NULL;
int ret = -1; int ret = -1;
char *pattern = NULL; g_autofree char *pattern = NULL;
char *buf = NULL; g_autofree char *buf = NULL;
virStreamPtr st = NULL; virStreamPtr st = NULL;
size_t i; size_t i;
virConnectPtr conn = NULL; virConnectPtr conn = NULL;
@ -292,9 +289,6 @@ static int testFDStreamWriteCommon(const char *scratchdir, bool blocking)
unlink(file); unlink(file);
if (conn) if (conn)
virConnectClose(conn); virConnectClose(conn);
VIR_FREE(file);
VIR_FREE(pattern);
VIR_FREE(buf);
return ret; return ret;
} }

View File

@ -26,8 +26,8 @@ static int
testCompareXMLToXMLHelper(const void *data) testCompareXMLToXMLHelper(const void *data)
{ {
const struct testInfo *info = data; const struct testInfo *info = data;
char *xml_in = NULL; g_autofree char *xml_in = NULL;
char *xml_out = NULL; g_autofree char *xml_out = NULL;
int ret = -1; int ret = -1;
xml_in = g_strdup_printf("%s/genericxml2xmlindata/%s.xml", xml_in = g_strdup_printf("%s/genericxml2xmlindata/%s.xml",
@ -39,8 +39,6 @@ testCompareXMLToXMLHelper(const void *data)
info->different ? xml_out : xml_in, info->different ? xml_out : xml_in,
info->active_only, 0, info->active_only, 0,
info->expectResult); info->expectResult);
VIR_FREE(xml_in);
VIR_FREE(xml_out);
return ret; return ret;
} }

View File

@ -16,8 +16,8 @@
static int static int
testCompareXMLToXMLFiles(const char *xml) testCompareXMLToXMLFiles(const char *xml)
{ {
char *xmlData = NULL; g_autofree char *xmlData = NULL;
char *actual = NULL; g_autofree char *actual = NULL;
int ret = -1; int ret = -1;
virInterfaceDef *dev = NULL; virInterfaceDef *dev = NULL;
@ -38,8 +38,6 @@ testCompareXMLToXMLFiles(const char *xml)
ret = 0; ret = 0;
fail: fail:
VIR_FREE(xmlData);
VIR_FREE(actual);
virInterfaceDefFree(dev); virInterfaceDefFree(dev);
return ret; return ret;
} }
@ -48,14 +46,13 @@ static int
testCompareXMLToXMLHelper(const void *data) testCompareXMLToXMLHelper(const void *data)
{ {
int result = -1; int result = -1;
char *xml = NULL; g_autofree char *xml = NULL;
xml = g_strdup_printf("%s/interfaceschemadata/%s.xml", abs_srcdir, xml = g_strdup_printf("%s/interfaceschemadata/%s.xml", abs_srcdir,
(const char *)data); (const char *)data);
result = testCompareXMLToXMLFiles(xml); result = testCompareXMLToXMLFiles(xml);
VIR_FREE(xml);
return result; return result;
} }

View File

@ -26,8 +26,8 @@ testCompareXMLToConfigFiles(const char *xmlfile,
bool expectError) bool expectError)
{ {
int ret = -1; int ret = -1;
char *config = NULL; g_autofree char *config = NULL;
char *actualxml = NULL; g_autofree char *actualxml = NULL;
virDomainDef *vmdef = NULL; virDomainDef *vmdef = NULL;
if (virTestLoadFile(configfile, &config) < 0) if (virTestLoadFile(configfile, &config) < 0)
@ -51,8 +51,6 @@ testCompareXMLToConfigFiles(const char *xmlfile,
ret = 0; ret = 0;
fail: fail:
VIR_FREE(actualxml);
VIR_FREE(config);
virDomainDefFree(vmdef); virDomainDefFree(vmdef);
return ret; return ret;
} }
@ -67,8 +65,8 @@ testCompareXMLToConfigHelperLegacy(const void *data)
{ {
int result = -1; int result = -1;
const struct testInfo *info = data; const struct testInfo *info = data;
char *xml = NULL; g_autofree char *xml = NULL;
char *config = NULL; g_autofree char *config = NULL;
xml = g_strdup_printf("%s/lxcconf2xmldata/lxcconf2xml-%s.xml", xml = g_strdup_printf("%s/lxcconf2xmldata/lxcconf2xml-%s.xml",
abs_srcdir, info->name); abs_srcdir, info->name);
@ -77,8 +75,6 @@ testCompareXMLToConfigHelperLegacy(const void *data)
result = testCompareXMLToConfigFiles(xml, config, info->expectError); result = testCompareXMLToConfigFiles(xml, config, info->expectError);
VIR_FREE(xml);
VIR_FREE(config);
return result; return result;
} }
@ -87,8 +83,8 @@ testCompareXMLToConfigHelperV3(const void *data)
{ {
int result = -1; int result = -1;
const struct testInfo *info = data; const struct testInfo *info = data;
char *xml = NULL; g_autofree char *xml = NULL;
char *config = NULL; g_autofree char *config = NULL;
xml = g_strdup_printf("%s/lxcconf2xmldata/lxcconf2xml-%s.xml", xml = g_strdup_printf("%s/lxcconf2xmldata/lxcconf2xml-%s.xml",
abs_srcdir, info->name); abs_srcdir, info->name);
@ -97,8 +93,6 @@ testCompareXMLToConfigHelperV3(const void *data)
result = testCompareXMLToConfigFiles(xml, config, info->expectError); result = testCompareXMLToConfigFiles(xml, config, info->expectError);
VIR_FREE(xml);
VIR_FREE(config);
return result; return result;
} }

View File

@ -29,8 +29,8 @@ static int
testCompareXMLToXMLHelper(const void *data) testCompareXMLToXMLHelper(const void *data)
{ {
const struct testInfo *info = data; const struct testInfo *info = data;
char *xml_in = NULL; g_autofree char *xml_in = NULL;
char *xml_out = NULL; g_autofree char *xml_out = NULL;
int ret = -1; int ret = -1;
xml_in = g_strdup_printf("%s/lxcxml2xmldata/lxc-%s.xml", xml_in = g_strdup_printf("%s/lxcxml2xmldata/lxc-%s.xml",
@ -43,8 +43,6 @@ testCompareXMLToXMLHelper(const void *data)
info->active_only, info->active_only,
info->parse_flags, info->parse_flags,
TEST_COMPARE_DOM_XML2XML_RESULT_SUCCESS); TEST_COMPARE_DOM_XML2XML_RESULT_SUCCESS);
VIR_FREE(xml_in);
VIR_FREE(xml_out);
return ret; return ret;
} }

View File

@ -92,8 +92,8 @@ verifyMetadata(virDomainPtr dom,
const char *uri) const char *uri)
{ {
bool ret = false; bool ret = false;
char *metadataXML = NULL; g_autofree char *metadataXML = NULL;
char *metadataAPI = NULL; g_autofree char *metadataAPI = NULL;
if (!expectAPI) { if (!expectAPI) {
if ((metadataAPI = virDomainGetMetadata(dom, if ((metadataAPI = virDomainGetMetadata(dom,
@ -147,8 +147,6 @@ verifyMetadata(virDomainPtr dom,
ret = true; ret = true;
cleanup: cleanup:
VIR_FREE(metadataXML);
VIR_FREE(metadataAPI);
return ret; return ret;
} }
@ -214,7 +212,7 @@ static int
testTextMetadata(const void *data) testTextMetadata(const void *data)
{ {
const struct metadataTest *test = data; const struct metadataTest *test = data;
char *actual = NULL; g_autofree char *actual = NULL;
int ret = -1; int ret = -1;
if (virDomainSetMetadata(test->dom, test->type, test->data, NULL, NULL, 0) < 0) { if (virDomainSetMetadata(test->dom, test->type, test->data, NULL, NULL, 0) < 0) {
@ -236,7 +234,6 @@ testTextMetadata(const void *data)
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(actual);
return ret; return ret;
} }

View File

@ -16,8 +16,8 @@
static int static int
testCompareXMLToXMLFiles(const char *xml, const char *outfile) testCompareXMLToXMLFiles(const char *xml, const char *outfile)
{ {
char *xmlData = NULL; g_autofree char *xmlData = NULL;
char *actual = NULL; g_autofree char *actual = NULL;
int ret = -1; int ret = -1;
virNodeDeviceDef *dev = NULL; virNodeDeviceDef *dev = NULL;
virNodeDevCapsDef *caps; virNodeDevCapsDef *caps;
@ -59,8 +59,6 @@ testCompareXMLToXMLFiles(const char *xml, const char *outfile)
ret = 0; ret = 0;
fail: fail:
VIR_FREE(xmlData);
VIR_FREE(actual);
virNodeDeviceDefFree(dev); virNodeDeviceDefFree(dev);
return ret; return ret;
} }
@ -69,7 +67,7 @@ static int
testCompareXMLToXMLHelper(const void *data) testCompareXMLToXMLHelper(const void *data)
{ {
int result = -1; int result = -1;
char *xml = NULL; g_autofree char *xml = NULL;
g_autofree char *outfile = NULL; g_autofree char *outfile = NULL;
xml = g_strdup_printf("%s/nodedevschemadata/%s.xml", abs_srcdir, xml = g_strdup_printf("%s/nodedevschemadata/%s.xml", abs_srcdir,
@ -80,7 +78,6 @@ testCompareXMLToXMLHelper(const void *data)
result = testCompareXMLToXMLFiles(xml, outfile); result = testCompareXMLToXMLFiles(xml, outfile);
VIR_FREE(xml);
return result; return result;
} }

View File

@ -118,7 +118,7 @@ testGetHostByName(const void *opaque)
i = 0; i = 0;
while (*addrList) { while (*addrList) {
virSocketAddr sa; virSocketAddr sa;
char *ipAddr; g_autofree char *ipAddr = NULL;
void *address = *addrList; void *address = *addrList;
memset(&sa, 0, sizeof(sa)); memset(&sa, 0, sizeof(sa));
@ -138,10 +138,8 @@ testGetHostByName(const void *opaque)
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
"Unexpected address %s, expecting %s", "Unexpected address %s, expecting %s",
ipAddr, NULLSTR(data->ipAddr[i])); ipAddr, NULLSTR(data->ipAddr[i]));
VIR_FREE(ipAddr);
return -1; return -1;
} }
VIR_FREE(ipAddr);
addrList++; addrList++;
i++; i++;

View File

@ -38,8 +38,8 @@ testReadConfigParam(const void *data G_GNUC_UNUSED)
{ {
int result = -1; int result = -1;
size_t i; size_t i;
char *conf = NULL; g_autofree char *conf = NULL;
char *value = NULL; g_autofree char *value = NULL;
conf = g_strdup_printf("%s/openvzutilstest.conf", abs_srcdir); conf = g_strdup_printf("%s/openvzutilstest.conf", abs_srcdir);
@ -61,8 +61,6 @@ testReadConfigParam(const void *data G_GNUC_UNUSED)
result = 0; result = 0;
cleanup: cleanup:
VIR_FREE(conf);
VIR_FREE(value);
return result; return result;
} }
@ -72,7 +70,7 @@ testReadNetworkConf(const void *data G_GNUC_UNUSED)
{ {
int result = -1; int result = -1;
virDomainDef *def = NULL; virDomainDef *def = NULL;
char *actual = NULL; g_autofree char *actual = NULL;
const char *expected = const char *expected =
"<domain type='openvz'>\n" "<domain type='openvz'>\n"
" <uuid>00000000-0000-0000-0000-000000000000</uuid>\n" " <uuid>00000000-0000-0000-0000-000000000000</uuid>\n"
@ -133,7 +131,6 @@ testReadNetworkConf(const void *data G_GNUC_UNUSED)
cleanup: cleanup:
virObjectUnref(driver.xmlopt); virObjectUnref(driver.xmlopt);
virObjectUnref(driver.caps); virObjectUnref(driver.caps);
VIR_FREE(actual);
virDomainDefFree(def); virDomainDefFree(def);
return result; return result;

View File

@ -67,8 +67,8 @@ static int
create_scsihost(const char *fakesysfsdir, const char *devicepath, create_scsihost(const char *fakesysfsdir, const char *devicepath,
const char *unique_id, const char *hostname) const char *unique_id, const char *hostname)
{ {
char *unique_id_path = NULL; g_autofree char *unique_id_path = NULL;
char *link_path = NULL; g_autofree char *link_path = NULL;
char *spot; char *spot;
int ret = -1; int ret = -1;
int fd = -1; int fd = -1;
@ -137,8 +137,6 @@ create_scsihost(const char *fakesysfsdir, const char *devicepath,
cleanup: cleanup:
VIR_FORCE_CLOSE(fd); VIR_FORCE_CLOSE(fd);
VIR_FREE(unique_id_path);
VIR_FREE(link_path);
return ret; return ret;
} }
@ -242,8 +240,8 @@ static int
mymain(void) mymain(void)
{ {
int ret = -1; int ret = -1;
char *fakerootdir = NULL; g_autofree char *fakerootdir = NULL;
char *fakesysfsdir = NULL; g_autofree char *fakesysfsdir = NULL;
fakerootdir = g_strdup(FAKEROOTDIRTEMPLATE); fakerootdir = g_strdup(FAKEROOTDIRTEMPLATE);
@ -279,8 +277,6 @@ mymain(void)
cleanup: cleanup:
if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL) if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL)
virFileDeleteTree(fakerootdir); virFileDeleteTree(fakerootdir);
VIR_FREE(fakerootdir);
VIR_FREE(fakesysfsdir);
VIR_FREE(scsihost_class_path); VIR_FREE(scsihost_class_path);
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
} }

View File

@ -34,8 +34,8 @@ static int
testCompareXMLToXMLHelper(const void *data) testCompareXMLToXMLHelper(const void *data)
{ {
int result = -1; int result = -1;
char *inxml = NULL; g_autofree char *inxml = NULL;
char *outxml = NULL; g_autofree char *outxml = NULL;
const struct testInfo *info = data; const struct testInfo *info = data;
inxml = g_strdup_printf("%s/secretxml2xmlin/%s.xml", abs_srcdir, info->name); inxml = g_strdup_printf("%s/secretxml2xmlin/%s.xml", abs_srcdir, info->name);
@ -46,9 +46,6 @@ testCompareXMLToXMLHelper(const void *data)
result = testCompareXMLToXMLFiles(inxml, outxml); result = testCompareXMLToXMLFiles(inxml, outxml);
VIR_FREE(inxml);
VIR_FREE(outxml);
return result; return result;
} }

View File

@ -59,7 +59,7 @@ testUserXattrEnabled(void)
int ret = -1; int ret = -1;
ssize_t len; ssize_t len;
const char *con_value = "system_u:object_r:svirt_image_t:s0:c41,c264"; 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); path = g_strdup_printf("%s/securityselinuxlabeldata/testxattr", abs_builddir);
if (g_mkdir_with_parents(abs_builddir "/securityselinuxlabeldata", 0777) < 0 || if (g_mkdir_with_parents(abs_builddir "/securityselinuxlabeldata", 0777) < 0 ||
@ -79,7 +79,6 @@ testUserXattrEnabled(void)
cleanup: cleanup:
unlink(path); unlink(path);
rmdir(abs_builddir "/securityselinuxlabeldata"); rmdir(abs_builddir "/securityselinuxlabeldata");
VIR_FREE(path);
return ret; return ret;
} }
@ -101,9 +100,9 @@ testSELinuxLoadFileList(const char *testname,
size_t *nfiles) size_t *nfiles)
{ {
int ret = -1; int ret = -1;
char *path = NULL; g_autofree char *path = NULL;
FILE *fp = NULL; FILE *fp = NULL;
char *line = NULL; g_autofree char *line = NULL;
*files = NULL; *files = NULL;
*nfiles = 0; *nfiles = 0;
@ -153,8 +152,6 @@ testSELinuxLoadFileList(const char *testname,
cleanup: cleanup:
VIR_FORCE_FCLOSE(fp); VIR_FORCE_FCLOSE(fp);
VIR_FREE(path);
VIR_FREE(line);
return ret; return ret;
} }

View File

@ -43,7 +43,7 @@ static int testParse(virSocketAddr *addr, const char *addrstr, int family, bool
static int testFormat(virSocketAddr *addr, const char *addrstr, bool pass) static int testFormat(virSocketAddr *addr, const char *addrstr, bool pass)
{ {
char *newaddrstr; g_autofree char *newaddrstr = NULL;
newaddrstr = virSocketAddrFormat(addr); newaddrstr = virSocketAddrFormat(addr);
if (!newaddrstr) if (!newaddrstr)
@ -51,10 +51,8 @@ static int testFormat(virSocketAddr *addr, const char *addrstr, bool pass)
if (STRNEQ(newaddrstr, addrstr)) { if (STRNEQ(newaddrstr, addrstr)) {
virTestDifference(stderr, addrstr, newaddrstr); virTestDifference(stderr, addrstr, newaddrstr);
VIR_FREE(newaddrstr);
return pass ? -1 : 0; return pass ? -1 : 0;
} else { } else {
VIR_FREE(newaddrstr);
return pass ? 0 : -1; return pass ? 0 : -1;
} }
} }

View File

@ -39,15 +39,13 @@ testLXCCapsInit(void)
if (virTestGetDebug()) { if (virTestGetDebug()) {
char *caps_str; g_autofree char *caps_str = NULL;
caps_str = virCapabilitiesFormatXML(caps); caps_str = virCapabilitiesFormatXML(caps);
if (!caps_str) if (!caps_str)
goto error; goto error;
VIR_TEST_DEBUG("LXC driver capabilities:\n%s", caps_str); VIR_TEST_DEBUG("LXC driver capabilities:\n%s", caps_str);
VIR_FREE(caps_str);
} }
return caps; return caps;

View File

@ -46,9 +46,9 @@ testFilterXML(char *xml)
static int static int
testCompareXMLtoXMLFiles(const char *xml) testCompareXMLtoXMLFiles(const char *xml)
{ {
char *xmlData = NULL; g_autofree char *xmlData = NULL;
char *actual = NULL; g_autofree char *actual = NULL;
char *pathResult = NULL; g_autofree char *pathResult = NULL;
int ret = -1; int ret = -1;
virVBoxSnapshotConfMachine *machine = NULL; virVBoxSnapshotConfMachine *machine = NULL;
@ -84,10 +84,7 @@ testCompareXMLtoXMLFiles(const char *xml)
cleanup: cleanup:
unlink(pathResult); unlink(pathResult);
rmdir(abs_builddir "/vboxsnapshotxmldata"); rmdir(abs_builddir "/vboxsnapshotxmldata");
VIR_FREE(xmlData);
VIR_FREE(actual);
virVBoxSnapshotConfMachineFree(machine); virVBoxSnapshotConfMachineFree(machine);
VIR_FREE(pathResult);
return ret; return ret;
} }
@ -96,14 +93,13 @@ static int
testCompareXMLToXMLHelper(const void *data) testCompareXMLToXMLHelper(const void *data)
{ {
int result = -1; int result = -1;
char *xml = NULL; g_autofree char *xml = NULL;
xml = g_strdup_printf("%s/vboxsnapshotxmldata/%s.vbox", abs_srcdir, xml = g_strdup_printf("%s/vboxsnapshotxmldata/%s.vbox", abs_srcdir,
(const char *)data); (const char *)data);
result = testCompareXMLtoXMLFiles(xml); result = testCompareXMLtoXMLFiles(xml);
VIR_FREE(xml);
return result; return result;
} }

View File

@ -38,8 +38,8 @@ testVerStrParse(const void *data)
{ {
const struct testInfo *info = data; const struct testInfo *info = data;
int ret = -1; int ret = -1;
char *path = NULL; g_autofree char *path = NULL;
char *databuf = NULL; g_autofree char *databuf = NULL;
unsigned long version; unsigned long version;
int vmware_type; int vmware_type;
@ -63,8 +63,6 @@ testVerStrParse(const void *data)
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(path);
VIR_FREE(databuf);
return ret; return ret;
} }

View File

@ -119,7 +119,7 @@ static int
testUnicode(const void *opaque G_GNUC_UNUSED) testUnicode(const void *opaque G_GNUC_UNUSED)
{ {
int ret = 0; int ret = 0;
char *act = NULL; g_autofree char *act = NULL;
const char *exp = const char *exp =
" Id 名稱 государство\n" " Id 名稱 государство\n"
@ -141,7 +141,6 @@ testUnicode(const void *opaque G_GNUC_UNUSED)
ret = -1; ret = -1;
cleanup: cleanup:
VIR_FREE(act);
vshTableFree(table); vshTableFree(table);
return ret; return ret;
} }
@ -151,7 +150,7 @@ static int
testUnicodeArabic(const void *opaque G_GNUC_UNUSED) testUnicodeArabic(const void *opaque G_GNUC_UNUSED)
{ {
int ret = 0; int ret = 0;
char *act = NULL; g_autofree char *act = NULL;
const char *exp = const char *exp =
" ﻡﺍ ﻢﻣﺍ ﻕﺎﺌﻣﺓ ﺓ ﺎﻠﺼﻋ ﺍﻸﺜﻧﺎﻧ\n" " ﻡﺍ ﻢﻣﺍ ﻕﺎﺌﻣﺓ ﺓ ﺎﻠﺼﻋ ﺍﻸﺜﻧﺎﻧ\n"
@ -184,7 +183,6 @@ testUnicodeArabic(const void *opaque G_GNUC_UNUSED)
ret = -1; ret = -1;
cleanup: cleanup:
VIR_FREE(act);
vshTableFree(table); vshTableFree(table);
return ret; return ret;
} }
@ -200,7 +198,7 @@ testUnicodeZeroWidthChar(const void *opaque G_GNUC_UNUSED)
"--------------------------\n" "--------------------------\n"
" 1\u200B fedora28 run\u200Bning\n" " 1\u200B fedora28 run\u200Bning\n"
" 2 rhel7.5 running\n"; " 2 rhel7.5 running\n";
char *act = NULL; g_autofree char *act = NULL;
wchar_t wc; wchar_t wc;
/* If this char is not classed as printable, the actual /* If this char is not classed as printable, the actual
@ -222,7 +220,6 @@ testUnicodeZeroWidthChar(const void *opaque G_GNUC_UNUSED)
ret = -1; ret = -1;
cleanup: cleanup:
VIR_FREE(act);
vshTableFree(table); vshTableFree(table);
return ret; return ret;
} }
@ -237,7 +234,7 @@ testUnicodeCombiningChar(const void *opaque G_GNUC_UNUSED)
"--------------------------\n" "--------------------------\n"
" 1 fědora28 running\n" " 1 fědora28 running\n"
" 2 rhel running\n"; " 2 rhel running\n";
char *act = NULL; g_autofree char *act = NULL;
table = vshTableNew("Id", "Náme", "Ⓢtatus", NULL); table = vshTableNew("Id", "Náme", "Ⓢtatus", NULL);
if (!table) if (!table)
@ -250,7 +247,6 @@ testUnicodeCombiningChar(const void *opaque G_GNUC_UNUSED)
ret = -1; ret = -1;
cleanup: cleanup:
VIR_FREE(act);
vshTableFree(table); vshTableFree(table);
return ret; return ret;
} }
@ -266,7 +262,7 @@ testUnicodeNonPrintableChar(const void *opaque G_GNUC_UNUSED)
"----------------------------------\n" "----------------------------------\n"
" 1 f\\x07edora28 running\n" " 1 f\\x07edora28 running\n"
" 2 rhel7.5 running\n"; " 2 rhel7.5 running\n";
char *act = NULL; g_autofree char *act = NULL;
table = vshTableNew("I\td", "Name", "Status", NULL); table = vshTableNew("I\td", "Name", "Status", NULL);
if (!table) if (!table)
@ -279,7 +275,6 @@ testUnicodeNonPrintableChar(const void *opaque G_GNUC_UNUSED)
ret = -1; ret = -1;
cleanup: cleanup:
VIR_FREE(act);
vshTableFree(table); vshTableFree(table);
return ret; return ret;
} }
@ -307,9 +302,9 @@ testNTables(const void *opaque G_GNUC_UNUSED)
" 2\n" " 2\n"
" 3\n" " 3\n"
" 4\n"; " 4\n";
char *act1 = NULL; g_autofree char *act1 = NULL;
char *act2 = NULL; g_autofree char *act2 = NULL;
char *act3 = NULL; g_autofree char *act3 = NULL;
table1 = vshTableNew("Id", "Name", "Status", NULL); table1 = vshTableNew("Id", "Name", "Status", NULL);
if (!table1) if (!table1)
@ -341,9 +336,6 @@ testNTables(const void *opaque G_GNUC_UNUSED)
ret = -1; ret = -1;
cleanup: cleanup:
VIR_FREE(act1);
VIR_FREE(act2);
VIR_FREE(act3);
vshTableFree(table1); vshTableFree(table1);
vshTableFree(table2); vshTableFree(table2);
vshTableFree(table3); vshTableFree(table3);