tests: vir: 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:31 +02:00
parent 5679b6283b
commit 526551ac0a
24 changed files with 65 additions and 140 deletions

View File

@ -174,7 +174,7 @@ testCgroupDetectMounts(const void *args)
{ {
int result = -1; int result = -1;
const struct _detectMountsData *data = args; const struct _detectMountsData *data = args;
char *parsed = NULL; g_autofree char *parsed = NULL;
const char *actual; const char *actual;
g_autoptr(virCgroup) group = NULL; g_autoptr(virCgroup) group = NULL;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER; g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
@ -209,7 +209,6 @@ testCgroupDetectMounts(const void *args)
cleanup: cleanup:
g_unsetenv("VIR_CGROUP_MOCK_FILENAME"); g_unsetenv("VIR_CGROUP_MOCK_FILENAME");
VIR_FREE(parsed);
return result; return result;
} }

View File

@ -70,7 +70,7 @@ static int testConfMemoryNoNewline(const void *opaque G_GNUC_UNUSED)
int ret = -1; int ret = -1;
virConfValue *val; virConfValue *val;
unsigned long long llvalue; unsigned long long llvalue;
char *str = NULL; g_autofree char *str = NULL;
int uintvalue; int uintvalue;
if (!conf) if (!conf)
@ -119,7 +119,6 @@ static int testConfMemoryNoNewline(const void *opaque G_GNUC_UNUSED)
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(str);
return ret; return ret;
} }
@ -341,7 +340,7 @@ static int testConfParseString(const void *opaque G_GNUC_UNUSED)
int ret = -1; int ret = -1;
g_autoptr(virConf) conf = virConfReadString(srcdata, 0); g_autoptr(virConf) conf = virConfReadString(srcdata, 0);
char *str = NULL; g_autofree char *str = NULL;
if (!conf) if (!conf)
return -1; return -1;
@ -367,7 +366,6 @@ static int testConfParseString(const void *opaque G_GNUC_UNUSED)
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(str);
return ret; return ret;
} }

View File

@ -37,7 +37,7 @@ static int
testCryptoHash(const void *opaque) testCryptoHash(const void *opaque)
{ {
const struct testCryptoHashData *data = opaque; const struct testCryptoHashData *data = opaque;
char *actual = NULL; g_autofree char *actual = NULL;
int ret = -1; int ret = -1;
if (virCryptoHashString(data->hash, data->input, &actual) < 0) { if (virCryptoHashString(data->hash, data->input, &actual) < 0) {
@ -53,7 +53,6 @@ testCryptoHash(const void *opaque)
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(actual);
return ret; return ret;
} }
@ -70,11 +69,11 @@ static int
testCryptoEncrypt(const void *opaque) testCryptoEncrypt(const void *opaque)
{ {
const struct testCryptoEncryptData *data = opaque; const struct testCryptoEncryptData *data = opaque;
uint8_t *enckey = NULL; g_autofree uint8_t *enckey = NULL;
size_t enckeylen = 32; size_t enckeylen = 32;
uint8_t *iv = NULL; g_autofree uint8_t *iv = NULL;
size_t ivlen = 16; size_t ivlen = 16;
uint8_t *ciphertext = NULL; g_autofree uint8_t *ciphertext = NULL;
size_t ciphertextlen = 0; size_t ciphertextlen = 0;
int ret = -1; int ret = -1;
@ -110,9 +109,6 @@ testCryptoEncrypt(const void *opaque)
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(enckey);
VIR_FREE(iv);
VIR_FREE(ciphertext);
return ret; return ret;
} }

View File

@ -112,14 +112,13 @@ testFileCacheLoadFile(const char *filename,
bool *outdated G_GNUC_UNUSED) bool *outdated G_GNUC_UNUSED)
{ {
testFileCacheObj *obj; testFileCacheObj *obj;
char *data; g_autofree char *data = NULL;
if (virFileReadAll(filename, 20, &data) < 0) if (virFileReadAll(filename, 20, &data) < 0)
return NULL; return NULL;
obj = testFileCacheObjNew(data); obj = testFileCacheObjNew(data);
VIR_FREE(data);
return obj; return obj;
} }

View File

@ -105,7 +105,7 @@ statfs_mock(const char *mtab,
FILE *f; FILE *f;
struct mntent mb; struct mntent mb;
char mntbuf[1024]; char mntbuf[1024];
char *canonPath = NULL; g_autofree char *canonPath = NULL;
int ret = -1; int ret = -1;
if (!(f = real_setmntent(mtab, "r"))) { if (!(f = real_setmntent(mtab, "r"))) {
@ -158,7 +158,6 @@ statfs_mock(const char *mtab,
} }
endmntent(f); endmntent(f);
VIR_FREE(canonPath);
return ret; return ret;
} }

View File

@ -104,7 +104,7 @@ testFileSanitizePath(const void *opaque)
{ {
const struct testFileSanitizePathData *data = opaque; const struct testFileSanitizePathData *data = opaque;
int ret = -1; int ret = -1;
char *actual; g_autofree char *actual = NULL;
if (!(actual = virFileSanitizePath(data->path))) if (!(actual = virFileSanitizePath(data->path)))
return -1; return -1;
@ -117,7 +117,6 @@ testFileSanitizePath(const void *opaque)
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(actual);
return ret; return ret;
} }
@ -322,7 +321,7 @@ testFileIsSharedFSType(const void *opaque G_GNUC_UNUSED)
return EXIT_AM_SKIP; return EXIT_AM_SKIP;
#else #else
const struct testFileIsSharedFSType *data = opaque; const struct testFileIsSharedFSType *data = opaque;
char *mtabFile = NULL; g_autofree char *mtabFile = NULL;
bool actual; bool actual;
int ret = -1; int ret = -1;
@ -343,7 +342,6 @@ testFileIsSharedFSType(const void *opaque G_GNUC_UNUSED)
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(mtabFile);
g_unsetenv("LIBVIRT_MTAB"); g_unsetenv("LIBVIRT_MTAB");
return ret; return ret;
#endif #endif

View File

@ -31,7 +31,7 @@ linuxTestCompareFiles(const char *cpuinfofile,
const char *outputfile) const char *outputfile)
{ {
int ret = -1; int ret = -1;
char *actualData = NULL; g_autofree char *actualData = NULL;
virNodeInfo nodeinfo; virNodeInfo nodeinfo;
FILE *cpuinfo; FILE *cpuinfo;
@ -68,7 +68,6 @@ linuxTestCompareFiles(const char *cpuinfofile,
ret = 0; ret = 0;
fail: fail:
VIR_FREE(actualData);
return ret; return ret;
} }
@ -109,7 +108,7 @@ linuxCPUStatsCompareFiles(const char *cpustatfile,
const char *outfile) const char *outfile)
{ {
int ret = -1; int ret = -1;
char *actualData = NULL; g_autofree char *actualData = NULL;
FILE *cpustat = NULL; FILE *cpustat = NULL;
virNodeCPUStatsPtr params = NULL; virNodeCPUStatsPtr params = NULL;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER; g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
@ -150,7 +149,6 @@ linuxCPUStatsCompareFiles(const char *cpustatfile,
fail: fail:
VIR_FORCE_FCLOSE(cpustat); VIR_FORCE_FCLOSE(cpustat);
VIR_FREE(actualData);
VIR_FREE(params); VIR_FREE(params);
return ret; return ret;
} }
@ -165,9 +163,9 @@ static int
linuxTestHostCPU(const void *opaque) linuxTestHostCPU(const void *opaque)
{ {
int result = -1; int result = -1;
char *cpuinfo = NULL; g_autofree char *cpuinfo = NULL;
char *sysfs_prefix = NULL; g_autofree char *sysfs_prefix = NULL;
char *output = NULL; g_autofree char *output = NULL;
struct linuxTestHostCPUData *data = (struct linuxTestHostCPUData *) opaque; struct linuxTestHostCPUData *data = (struct linuxTestHostCPUData *) opaque;
const char *archStr = virArchToString(data->arch); const char *archStr = virArchToString(data->arch);
@ -182,10 +180,6 @@ linuxTestHostCPU(const void *opaque)
result = linuxTestCompareFiles(cpuinfo, data->arch, output); result = linuxTestCompareFiles(cpuinfo, data->arch, output);
virFileWrapperRemovePrefix(SYSFS_SYSTEM_PATH); virFileWrapperRemovePrefix(SYSFS_SYSTEM_PATH);
VIR_FREE(cpuinfo);
VIR_FREE(output);
VIR_FREE(sysfs_prefix);
return result; return result;
} }
@ -232,8 +226,8 @@ linuxTestNodeCPUStats(const void *data)
{ {
const struct nodeCPUStatsData *testData = data; const struct nodeCPUStatsData *testData = data;
int result = -1; int result = -1;
char *cpustatfile = NULL; g_autofree char *cpustatfile = NULL;
char *outfile = NULL; g_autofree g_autofree char *outfile = NULL;
cpustatfile = g_strdup_printf("%s/virhostcpudata/linux-cpustat-%s.stat", cpustatfile = g_strdup_printf("%s/virhostcpudata/linux-cpustat-%s.stat",
abs_srcdir, testData->name); abs_srcdir, testData->name);
@ -255,9 +249,6 @@ linuxTestNodeCPUStats(const void *data)
} }
} }
VIR_FREE(cpustatfile);
VIR_FREE(outfile);
return result; return result;
} }

View File

@ -210,7 +210,7 @@ testISCSIGetSession(const void *data)
{ {
const struct testSessionInfo *info = data; const struct testSessionInfo *info = data;
struct testIscsiadmCbData cbData = { 0 }; struct testIscsiadmCbData cbData = { 0 };
char *actual_session = NULL; g_autofree char *actual_session = NULL;
int ret = -1; int ret = -1;
g_autoptr(virCommandDryRunToken) dryRunToken = virCommandDryRunTokenNew(); g_autoptr(virCommandDryRunToken) dryRunToken = virCommandDryRunTokenNew();
@ -231,7 +231,6 @@ testISCSIGetSession(const void *data)
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(actual_session);
return ret; return ret;
} }

View File

@ -35,7 +35,7 @@ static int
checkOutput(virBuffer *buf, const char *exp_cmd) checkOutput(virBuffer *buf, const char *exp_cmd)
{ {
int ret = -1; int ret = -1;
char *actual_cmd = NULL; g_autofree char *actual_cmd = NULL;
if (!(actual_cmd = virBufferContentAndReset(buf))) { if (!(actual_cmd = virBufferContentAndReset(buf))) {
fprintf(stderr, "cannot compare buffer to exp: %s", exp_cmd); fprintf(stderr, "cannot compare buffer to exp: %s", exp_cmd);
@ -50,7 +50,6 @@ checkOutput(virBuffer *buf, const char *exp_cmd)
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(actual_cmd);
return ret; return ret;
} }
@ -59,7 +58,7 @@ static int
testKModLoad(const void *args G_GNUC_UNUSED) testKModLoad(const void *args G_GNUC_UNUSED)
{ {
int ret = -1; int ret = -1;
char *errbuf = NULL; g_autofree char *errbuf = NULL;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER; g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
g_autoptr(virCommandDryRunToken) dryRunToken = virCommandDryRunTokenNew(); g_autoptr(virCommandDryRunToken) dryRunToken = virCommandDryRunTokenNew();
@ -77,7 +76,6 @@ testKModLoad(const void *args G_GNUC_UNUSED)
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(errbuf);
return ret; return ret;
} }
@ -86,7 +84,7 @@ static int
testKModUnload(const void *args G_GNUC_UNUSED) testKModUnload(const void *args G_GNUC_UNUSED)
{ {
int ret = -1; int ret = -1;
char *errbuf = NULL; g_autofree char *errbuf = NULL;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER; g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
g_autoptr(virCommandDryRunToken) dryRunToken = virCommandDryRunTokenNew(); g_autoptr(virCommandDryRunToken) dryRunToken = virCommandDryRunTokenNew();
@ -104,7 +102,6 @@ testKModUnload(const void *args G_GNUC_UNUSED)
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(errbuf);
return ret; return ret;
} }

View File

@ -39,7 +39,7 @@ testMACLookup(const void *opaque)
GSList *macs; GSList *macs;
GSList *next; GSList *next;
size_t i, j; size_t i, j;
char *file = NULL; g_autofree char *file = NULL;
int ret = -1; int ret = -1;
file = g_strdup_printf("%s/virmacmaptestdata/%s.json", abs_srcdir, data->file); file = g_strdup_printf("%s/virmacmaptestdata/%s.json", abs_srcdir, data->file);
@ -78,7 +78,6 @@ testMACLookup(const void *opaque)
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(file);
return ret; return ret;
} }
@ -90,7 +89,7 @@ testMACRemove(const void *opaque)
g_autoptr(virMacMap) mgr = NULL; g_autoptr(virMacMap) mgr = NULL;
GSList *macs; GSList *macs;
size_t i; size_t i;
char *file = NULL; g_autofree char *file = NULL;
int ret = -1; int ret = -1;
file = g_strdup_printf("%s/virmacmaptestdata/%s.json", abs_srcdir, data->file); file = g_strdup_printf("%s/virmacmaptestdata/%s.json", abs_srcdir, data->file);
@ -115,7 +114,6 @@ testMACRemove(const void *opaque)
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(file);
return ret; return ret;
} }
@ -124,8 +122,8 @@ static int
testMACFlush(const void *opaque) testMACFlush(const void *opaque)
{ {
const struct testData *data = opaque; const struct testData *data = opaque;
char *file = NULL; g_autofree char *file = NULL;
char *str = NULL; g_autofree char *str = NULL;
int ret = -1; int ret = -1;
file = g_strdup_printf("%s/virmacmaptestdata/%s.json", abs_srcdir, data->file); file = g_strdup_printf("%s/virmacmaptestdata/%s.json", abs_srcdir, data->file);
@ -138,8 +136,6 @@ testMACFlush(const void *opaque)
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(file);
VIR_FREE(str);
return ret; return ret;
} }

View File

@ -270,10 +270,10 @@ static int testExecRestart(const void *opaque)
int ret = -1; int ret = -1;
virNetDaemon *dmn = NULL; virNetDaemon *dmn = NULL;
const struct testExecRestartData *data = opaque; const struct testExecRestartData *data = opaque;
char *infile = NULL; g_autofree char *infile = NULL;
char *outfile = NULL; g_autofree char *outfile = NULL;
char *injsonstr = NULL; g_autofree char *injsonstr = NULL;
char *outjsonstr = NULL; g_autofree char *outjsonstr = NULL;
virJSONValue *injson = NULL; virJSONValue *injson = NULL;
virJSONValue *outjson = NULL; virJSONValue *outjson = NULL;
int fdclient[2] = { -1, -1 }, fdserver[2] = { -1, -1 }; int fdclient[2] = { -1, -1 }, fdserver[2] = { -1, -1 };
@ -352,10 +352,6 @@ static int testExecRestart(const void *opaque)
VIR_TEST_DEBUG("Test should have failed"); VIR_TEST_DEBUG("Test should have failed");
ret = -1; ret = -1;
} }
VIR_FREE(infile);
VIR_FREE(outfile);
VIR_FREE(injsonstr);
VIR_FREE(outjsonstr);
virJSONValueFree(injson); virJSONValueFree(injson);
virJSONValueFree(outjson); virJSONValueFree(outjson);
virObjectUnref(dmn); virObjectUnref(dmn);

View File

@ -178,7 +178,7 @@ testSocketAccept(const void *opaque)
int ret = -1; int ret = -1;
char portstr[100]; char portstr[100];
char *tmpdir = NULL; char *tmpdir = NULL;
char *path = NULL; g_autofree char *path = NULL;
char template[] = "/tmp/libvirt_XXXXXX"; char template[] = "/tmp/libvirt_XXXXXX";
virThread th; virThread th;
struct testClientData cdata = { 0 }; struct testClientData cdata = { 0 };
@ -288,7 +288,6 @@ testSocketAccept(const void *opaque)
virObjectUnref(lsock[i]); virObjectUnref(lsock[i]);
} }
VIR_FREE(lsock); VIR_FREE(lsock);
VIR_FREE(path);
if (tmpdir) if (tmpdir)
rmdir(tmpdir); rmdir(tmpdir);
return ret; return ret;
@ -304,7 +303,7 @@ static int testSocketUNIXAddrs(const void *data G_GNUC_UNUSED)
virNetSocket *csock = NULL; /* Client socket */ virNetSocket *csock = NULL; /* Client socket */
int ret = -1; int ret = -1;
char *path = NULL; g_autofree char *path = NULL;
char *tmpdir; char *tmpdir;
char template[] = "/tmp/libvirt_XXXXXX"; char template[] = "/tmp/libvirt_XXXXXX";
@ -375,7 +374,6 @@ static int testSocketUNIXAddrs(const void *data G_GNUC_UNUSED)
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(path);
virObjectUnref(lsock); virObjectUnref(lsock);
virObjectUnref(ssock); virObjectUnref(ssock);
virObjectUnref(csock); virObjectUnref(csock);

View File

@ -36,7 +36,7 @@
static int static int
testCompareXMLToXMLFiles(const char *expected) testCompareXMLToXMLFiles(const char *expected)
{ {
char *actual = NULL; g_autofree char *actual = NULL;
int ret = -1; int ret = -1;
g_autoptr(virNetworkPortDef) dev = NULL; g_autoptr(virNetworkPortDef) dev = NULL;
@ -51,7 +51,6 @@ testCompareXMLToXMLFiles(const char *expected)
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(actual);
return ret; return ret;
} }
@ -64,15 +63,12 @@ testCompareXMLToXMLHelper(const void *data)
{ {
const struct testInfo *info = data; const struct testInfo *info = data;
int ret = -1; int ret = -1;
char *xml = NULL; g_autofree char *xml = NULL;
xml = g_strdup_printf("%s/virnetworkportxml2xmldata/%s.xml", abs_srcdir, xml = g_strdup_printf("%s/virnetworkportxml2xmldata/%s.xml", abs_srcdir,
info->name); info->name);
ret = testCompareXMLToXMLFiles(xml); ret = testCompareXMLToXMLFiles(xml);
VIR_FREE(xml);
return ret; return ret;
} }

View File

@ -41,13 +41,11 @@ bool
virNumaIsAvailable(void) virNumaIsAvailable(void)
{ {
if (numa_avail < 0) { if (numa_avail < 0) {
char *sysfs_node_path = NULL; g_autofree char *sysfs_node_path = NULL;
sysfs_node_path = g_strdup_printf("%s/node", SYSFS_SYSTEM_PATH); sysfs_node_path = g_strdup_printf("%s/node", SYSFS_SYSTEM_PATH);
numa_avail = virFileExists(sysfs_node_path); numa_avail = virFileExists(sysfs_node_path);
VIR_FREE(sysfs_node_path);
} }
/* /*
@ -165,7 +163,7 @@ int
virNumaGetNodeCPUs(int node, virBitmap **cpus) virNumaGetNodeCPUs(int node, virBitmap **cpus)
{ {
int ret = -1; int ret = -1;
char *cpulist = NULL; g_autofree char *cpulist = NULL;
if (virFileReadValueString(&cpulist, if (virFileReadValueString(&cpulist,
"%s/node/node%u/cpulist", "%s/node/node%u/cpulist",
@ -183,6 +181,5 @@ virNumaGetNodeCPUs(int node, virBitmap **cpus)
ret = virBitmapCountBits(*cpus); ret = virBitmapCountBits(*cpus);
cleanup: cleanup:
VIR_FREE(cpulist);
return ret; return ret;
} }

View File

@ -38,7 +38,7 @@
static int static int
testCompareXMLToXMLFiles(const char *xml) testCompareXMLToXMLFiles(const char *xml)
{ {
char *actual = NULL; g_autofree char *actual = NULL;
int ret = -1; int ret = -1;
virNWFilterBindingDef *dev = NULL; virNWFilterBindingDef *dev = NULL;
@ -56,7 +56,6 @@ testCompareXMLToXMLFiles(const char *xml)
ret = 0; ret = 0;
fail: fail:
VIR_FREE(actual);
virNWFilterBindingDefFree(dev); virNWFilterBindingDefFree(dev);
return ret; return ret;
} }
@ -70,15 +69,13 @@ testCompareXMLToXMLHelper(const void *data)
{ {
int result = -1; int result = -1;
const test_parms *tp = data; const test_parms *tp = data;
char *xml = NULL; g_autofree char *xml = NULL;
xml = g_strdup_printf("%s/virnwfilterbindingxml2xmldata/%s.xml", abs_srcdir, xml = g_strdup_printf("%s/virnwfilterbindingxml2xmldata/%s.xml", abs_srcdir,
tp->name); tp->name);
result = testCompareXMLToXMLFiles(xml); result = testCompareXMLToXMLFiles(xml);
VIR_FREE(xml);
return result; return result;
} }

View File

@ -32,8 +32,8 @@
static int static int
testVirPCIDeviceCheckDriver(virPCIDevice *dev, const char *expected) testVirPCIDeviceCheckDriver(virPCIDevice *dev, const char *expected)
{ {
char *path = NULL; g_autofree char *path = NULL;
char *driver = NULL; g_autofree char *driver = NULL;
int ret = -1; int ret = -1;
if (virPCIDeviceGetDriverPathAndName(dev, &path, &driver) < 0) if (virPCIDeviceGetDriverPathAndName(dev, &path, &driver) < 0)
@ -49,8 +49,6 @@ testVirPCIDeviceCheckDriver(virPCIDevice *dev, const char *expected)
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(path);
VIR_FREE(driver);
return ret; return ret;
} }
@ -339,7 +337,7 @@ static int
mymain(void) mymain(void)
{ {
int ret = 0; int ret = 0;
char *fakerootdir; g_autofree char *fakerootdir = NULL;
fakerootdir = g_strdup(FAKEROOTDIRTEMPLATE); fakerootdir = g_strdup(FAKEROOTDIRTEMPLATE);
@ -361,12 +359,11 @@ mymain(void)
struct testPCIDevData data = { \ struct testPCIDevData data = { \
domain, bus, slot, function, NULL \ domain, bus, slot, function, NULL \
}; \ }; \
char *label = NULL; \ g_autofree char *label = NULL; \
label = g_strdup_printf("%s(%04x:%02x:%02x.%x)", \ label = g_strdup_printf("%s(%04x:%02x:%02x.%x)", \
#fnc, domain, bus, slot, function); \ #fnc, domain, bus, slot, function); \
if (virTestRun(label, fnc, &data) < 0) \ if (virTestRun(label, fnc, &data) < 0) \
ret = -1; \ ret = -1; \
VIR_FREE(label); \
} while (0) } while (0)
# define DO_TEST_PCI_DRIVER(domain, bus, slot, function, driver) \ # define DO_TEST_PCI_DRIVER(domain, bus, slot, function, driver) \
@ -374,14 +371,13 @@ mymain(void)
struct testPCIDevData data = { \ struct testPCIDevData data = { \
domain, bus, slot, function, driver \ domain, bus, slot, function, driver \
}; \ }; \
char *label = NULL; \ g_autofree char *label = NULL; \
label = g_strdup_printf("PCI driver %04x:%02x:%02x.%x is %s", \ label = g_strdup_printf("PCI driver %04x:%02x:%02x.%x is %s", \
domain, bus, slot, function, \ domain, bus, slot, function, \
NULLSTR(driver)); \ NULLSTR(driver)); \
if (virTestRun(label, testVirPCIDeviceCheckDriverTest, \ if (virTestRun(label, testVirPCIDeviceCheckDriverTest, \
&data) < 0) \ &data) < 0) \
ret = -1; \ ret = -1; \
VIR_FREE(label); \
} while (0) } while (0)
/* Changes made to individual devices are persistent and the /* Changes made to individual devices are persistent and the
@ -419,8 +415,6 @@ mymain(void)
if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL) if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL)
virFileDeleteTree(fakerootdir); virFileDeleteTree(fakerootdir);
VIR_FREE(fakerootdir);
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
} }

View File

@ -18,12 +18,12 @@ static int
test_virResctrlGetUnused(const void *opaque) test_virResctrlGetUnused(const void *opaque)
{ {
struct virResctrlData *data = (struct virResctrlData *) opaque; struct virResctrlData *data = (struct virResctrlData *) opaque;
char *system_dir = NULL; g_autofree char *system_dir = NULL;
char *resctrl_dir = NULL; g_autofree char *resctrl_dir = NULL;
int ret = -1; int ret = -1;
g_autoptr(virResctrlAlloc) alloc = NULL; g_autoptr(virResctrlAlloc) alloc = NULL;
char *schemata_str = NULL; g_autofree char *schemata_str = NULL;
char *schemata_file; g_autofree char *schemata_file = NULL;
g_autoptr(virCaps) caps = NULL; g_autoptr(virCaps) caps = NULL;
system_dir = g_strdup_printf("%s/vircaps2xmldata/linux-%s/system", abs_srcdir, system_dir = g_strdup_printf("%s/vircaps2xmldata/linux-%s/system", abs_srcdir,
@ -65,10 +65,6 @@ test_virResctrlGetUnused(const void *opaque)
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(system_dir);
VIR_FREE(resctrl_dir);
VIR_FREE(schemata_str);
VIR_FREE(schemata_file);
return ret; return ret;
} }

View File

@ -36,7 +36,7 @@ static char *virscsi_prefix;
static int static int
test1(const void *data G_GNUC_UNUSED) test1(const void *data G_GNUC_UNUSED)
{ {
char *name = NULL; g_autofree char *name = NULL;
int ret = -1; int ret = -1;
if (!(name = virSCSIDeviceGetDevName(virscsi_prefix, if (!(name = virSCSIDeviceGetDevName(virscsi_prefix,
@ -48,7 +48,6 @@ test1(const void *data G_GNUC_UNUSED)
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(name);
return ret; return ret;
} }
@ -66,7 +65,7 @@ test2(const void *data G_GNUC_UNUSED)
bool free_dev = true; bool free_dev = true;
bool free_dev1 = true; bool free_dev1 = true;
virSCSIDevice *tmp = NULL; virSCSIDevice *tmp = NULL;
char *sgname = NULL; g_autofree char *sgname = NULL;
int ret = -1; int ret = -1;
sgname = virSCSIDeviceGetSgName(virscsi_prefix, sgname = virSCSIDeviceGetSgName(virscsi_prefix,
@ -152,7 +151,6 @@ test2(const void *data G_GNUC_UNUSED)
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(sgname);
if (free_dev) if (free_dev)
virSCSIDeviceFree(dev); virSCSIDeviceFree(dev);
if (free_dev1) if (free_dev1)
@ -164,8 +162,8 @@ static int
create_symlink(const char *tmpdir, const char *src_name, const char *dst_name) create_symlink(const char *tmpdir, const char *src_name, const char *dst_name)
{ {
int ret = -1; int ret = -1;
char *src_path = NULL; g_autofree char *src_path = NULL;
char *dst_path = NULL; g_autofree char *dst_path = NULL;
src_path = g_strdup_printf("%s/%s", virscsi_prefix, src_name); src_path = g_strdup_printf("%s/%s", virscsi_prefix, src_name);
@ -179,9 +177,6 @@ create_symlink(const char *tmpdir, const char *src_name, const char *dst_name)
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(src_path);
VIR_FREE(dst_path);
return ret; return ret;
} }

View File

@ -222,7 +222,7 @@ static int
testStringReplace(const void *opaque G_GNUC_UNUSED) testStringReplace(const void *opaque G_GNUC_UNUSED)
{ {
const struct stringReplaceData *data = opaque; const struct stringReplaceData *data = opaque;
char *result; g_autofree char *result = NULL;
int ret = -1; int ret = -1;
result = virStringReplace(data->haystack, result = virStringReplace(data->haystack,
@ -238,7 +238,6 @@ testStringReplace(const void *opaque G_GNUC_UNUSED)
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(result);
return ret; return ret;
} }
@ -402,7 +401,7 @@ static int testStripIPv6Brackets(const void *args)
{ {
const struct testStripData *data = args; const struct testStripData *data = args;
int ret = -1; int ret = -1;
char *res = NULL; g_autofree char *res = NULL;
res = g_strdup(data->string); res = g_strdup(data->string);
@ -417,7 +416,6 @@ static int testStripIPv6Brackets(const void *args)
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(res);
return ret; return ret;
} }
@ -425,7 +423,7 @@ static int testStripControlChars(const void *args)
{ {
const struct testStripData *data = args; const struct testStripData *data = args;
int ret = -1; int ret = -1;
char *res = NULL; g_autofree char *res = NULL;
res = g_strdup(data->string); res = g_strdup(data->string);
@ -440,7 +438,6 @@ static int testStripControlChars(const void *args)
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(res);
return ret; return ret;
} }
@ -454,7 +451,7 @@ static int testFilterChars(const void *args)
{ {
const struct testFilterData *data = args; const struct testFilterData *data = args;
int ret = -1; int ret = -1;
char *res = NULL; g_autofree char *res = NULL;
res = g_strdup(data->string); res = g_strdup(data->string);
@ -469,7 +466,6 @@ static int testFilterChars(const void *args)
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(res);
return ret; return ret;
} }

View File

@ -325,7 +325,7 @@ static int testCreateNetwork(const void *opaque G_GNUC_UNUSED)
static int static int
testGetMachineName(const void *opaque G_GNUC_UNUSED) testGetMachineName(const void *opaque G_GNUC_UNUSED)
{ {
char *tmp = virSystemdGetMachineNameByPID(1234); g_autofree char *tmp = virSystemdGetMachineNameByPID(1234);
int ret = -1; int ret = -1;
if (!tmp) { if (!tmp) {
@ -336,7 +336,6 @@ testGetMachineName(const void *opaque G_GNUC_UNUSED)
if (STREQ(tmp, "qemu-demo")) if (STREQ(tmp, "qemu-demo"))
ret = 0; ret = 0;
VIR_FREE(tmp);
return ret; return ret;
} }
@ -371,7 +370,7 @@ testScopeName(const void *opaque)
{ {
const struct testNameData *data = opaque; const struct testNameData *data = opaque;
int ret = -1; int ret = -1;
char *actual = NULL; g_autofree char *actual = NULL;
if (!(actual = virSystemdMakeScopeName(data->name, "lxc", data->legacy))) if (!(actual = virSystemdMakeScopeName(data->name, "lxc", data->legacy)))
goto cleanup; goto cleanup;
@ -385,7 +384,6 @@ testScopeName(const void *opaque)
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(actual);
return ret; return ret;
} }
@ -394,7 +392,7 @@ testMachineName(const void *opaque)
{ {
const struct testNameData *data = opaque; const struct testNameData *data = opaque;
int ret = -1; int ret = -1;
char *actual = NULL; g_autofree char *actual = NULL;
if (!(actual = virDomainDriverGenerateMachineName("qemu", data->root, if (!(actual = virDomainDriverGenerateMachineName("qemu", data->root,
data->id, data->name, true))) data->id, data->name, true)))
@ -409,7 +407,6 @@ testMachineName(const void *opaque)
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(actual);
return ret; return ret;
} }

View File

@ -100,9 +100,9 @@ static void
checkPath(const char *path, checkPath(const char *path,
const char *func) const char *func)
{ {
char *fullPath = NULL; g_autofree char *fullPath = NULL;
char *relPath = NULL; g_autofree char *relPath = NULL;
char *crippledPath = NULL; g_autofree char *crippledPath = NULL;
if (!g_path_is_absolute(path)) if (!g_path_is_absolute(path))
relPath = g_strdup_printf("./%s", path); relPath = g_strdup_printf("./%s", path);
@ -130,10 +130,6 @@ checkPath(const char *path,
printFile(path, func); printFile(path, func);
} }
VIR_FREE(crippledPath);
VIR_FREE(relPath);
VIR_FREE(fullPath);
return; return;
} }

View File

@ -49,7 +49,7 @@ static int testURIParse(const void *args)
int ret = -1; int ret = -1;
virURI *uri = NULL; virURI *uri = NULL;
const struct URIParseData *data = args; const struct URIParseData *data = args;
char *uristr = NULL; g_autofree char *uristr = NULL;
size_t i; size_t i;
bool fail = false; bool fail = false;
@ -134,7 +134,6 @@ static int testURIParse(const void *args)
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(uristr);
virURIFree(uri); virURIFree(uri);
return ret; return ret;
} }

View File

@ -63,7 +63,7 @@ static char *get_fake_path(const char *real_path)
DIR *opendir(const char *name) DIR *opendir(const char *name)
{ {
char *path; g_autofree char *path = NULL;
DIR* ret; DIR* ret;
init_syms(); init_syms();
@ -71,13 +71,12 @@ DIR *opendir(const char *name)
path = get_fake_path(name); path = get_fake_path(name);
ret = realopendir(path); ret = realopendir(path);
VIR_FREE(path);
return ret; return ret;
} }
int open(const char *pathname, int flags, ...) int open(const char *pathname, int flags, ...)
{ {
char *path; g_autofree char *path = NULL;
int ret; int ret;
va_list ap; va_list ap;
mode_t mode = 0; mode_t mode = 0;
@ -98,7 +97,5 @@ int open(const char *pathname, int flags, ...)
} }
ret = realopen(path, flags, mode); ret = realopen(path, flags, mode);
VIR_FREE(path);
return ret; return ret;
} }

View File

@ -49,7 +49,7 @@ static int testDeviceFileActor(virUSBDevice *dev,
const char *path, const char *path,
void *opaque G_GNUC_UNUSED) void *opaque G_GNUC_UNUSED)
{ {
char *str = NULL; g_autofree char *str = NULL;
int ret = 0; int ret = 0;
str = g_strdup_printf(USB_DEVFS "%03d/%03d", virUSBDeviceGetBus(dev), str = g_strdup_printf(USB_DEVFS "%03d/%03d", virUSBDeviceGetBus(dev),
@ -61,7 +61,6 @@ static int testDeviceFileActor(virUSBDevice *dev,
path, str); path, str);
ret = -1; ret = -1;
} }
VIR_FREE(str);
return ret; return ret;
} }