tests: use g_autoptr instead of virObjectUnref

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-08-20 15:53:53 +02:00
parent a26df27662
commit d66fb7ac15
12 changed files with 24 additions and 48 deletions

View File

@ -526,7 +526,7 @@ cpuTestCPUID(bool guest, const void *arg)
g_autofree char *host = NULL; g_autofree char *host = NULL;
g_autoptr(virCPUDef) cpu = NULL; g_autoptr(virCPUDef) cpu = NULL;
g_autofree char *result = NULL; g_autofree char *result = NULL;
virDomainCapsCPUModels *models = NULL; g_autoptr(virDomainCapsCPUModels) models = NULL;
hostFile = g_strdup_printf("%s/cputestdata/%s-cpuid-%s.xml", abs_srcdir, hostFile = g_strdup_printf("%s/cputestdata/%s-cpuid-%s.xml", abs_srcdir,
virArchToString(data->arch), data->host); virArchToString(data->arch), data->host);
@ -563,7 +563,6 @@ cpuTestCPUID(bool guest, const void *arg)
ret = cpuTestCompareXML(data->arch, cpu, result); ret = cpuTestCompareXML(data->arch, cpu, result);
cleanup: cleanup:
virObjectUnref(models);
return ret; return ret;
} }
@ -728,8 +727,8 @@ cpuTestUpdateLive(const void *arg)
g_autoptr(virCPUData) disabledData = NULL; g_autoptr(virCPUData) disabledData = NULL;
g_autofree char *expectedFile = NULL; g_autofree char *expectedFile = NULL;
g_autoptr(virCPUDef) expected = NULL; g_autoptr(virCPUDef) expected = NULL;
virDomainCapsCPUModels *hvModels = NULL; g_autoptr(virDomainCapsCPUModels) hvModels = NULL;
virDomainCapsCPUModels *models = NULL; g_autoptr(virDomainCapsCPUModels) models = NULL;
int ret = -1; int ret = -1;
cpuFile = g_strdup_printf("cpuid-%s-guest", data->host); cpuFile = g_strdup_printf("cpuid-%s-guest", data->host);
@ -795,8 +794,6 @@ cpuTestUpdateLive(const void *arg)
ret = cpuTestUpdateLiveCompare(data->arch, cpu, expected); ret = cpuTestUpdateLiveCompare(data->arch, cpu, expected);
cleanup: cleanup:
virObjectUnref(hvModels);
virObjectUnref(models);
return ret; return ret;
} }

View File

@ -75,7 +75,7 @@ fillQemuCaps(virDomainCaps *domCaps,
{ {
int ret = -1; int ret = -1;
char *path = NULL; char *path = NULL;
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:
virObjectUnref(qemuCaps);
VIR_FREE(path); VIR_FREE(path);
return ret; return ret;
} }
@ -208,7 +207,7 @@ static int
test_virDomainCapsFormat(const void *opaque) test_virDomainCapsFormat(const void *opaque)
{ {
const struct testData *data = opaque; const struct testData *data = opaque;
virDomainCaps *domCaps = NULL; g_autoptr(virDomainCaps) domCaps = NULL;
char *path = NULL; char *path = NULL;
char *domCapsXML = NULL; char *domCapsXML = NULL;
int ret = -1; int ret = -1;
@ -256,7 +255,6 @@ test_virDomainCapsFormat(const void *opaque)
cleanup: cleanup:
VIR_FREE(domCapsXML); VIR_FREE(domCapsXML);
VIR_FREE(path); VIR_FREE(path);
virObjectUnref(domCaps);
return ret; return ret;
} }

View File

@ -27,7 +27,7 @@ testCompareXMLToConfFiles(const char *inxml, const char *outconf,
virCommand *cmd = NULL; virCommand *cmd = NULL;
char *pidfile = NULL; char *pidfile = NULL;
dnsmasqContext *dctx = NULL; dnsmasqContext *dctx = NULL;
virNetworkXMLOption *xmlopt = NULL; g_autoptr(virNetworkXMLOption) xmlopt = NULL;
if (!(xmlopt = networkDnsmasqCreateXMLConf())) if (!(xmlopt = networkDnsmasqCreateXMLConf()))
goto fail; goto fail;
@ -85,7 +85,6 @@ testCompareXMLToConfFiles(const char *inxml, const char *outconf,
VIR_FREE(hostsfileactual); VIR_FREE(hostsfileactual);
VIR_FREE(pidfile); VIR_FREE(pidfile);
virCommandFree(cmd); virCommandFree(cmd);
virObjectUnref(xmlopt);
virNetworkObjEndAPI(&obj); virNetworkObjEndAPI(&obj);
dnsmasqContextFree(dctx); dnsmasqContextFree(dctx);
return ret; return ret;

View File

@ -30,7 +30,7 @@ testCompareXMLToXMLFiles(const char *inxml, const char *outxml,
int ret; int ret;
testCompareNetXML2XMLResult result = TEST_COMPARE_NET_XML2XML_RESULT_SUCCESS; testCompareNetXML2XMLResult result = TEST_COMPARE_NET_XML2XML_RESULT_SUCCESS;
virNetworkDef *dev = NULL; virNetworkDef *dev = NULL;
virNetworkXMLOption *xmlopt = NULL; g_autoptr(virNetworkXMLOption) xmlopt = NULL;
if (!(xmlopt = networkDnsmasqCreateXMLConf())) if (!(xmlopt = networkDnsmasqCreateXMLConf()))
goto cleanup; goto cleanup;
@ -72,7 +72,6 @@ testCompareXMLToXMLFiles(const char *inxml, const char *outxml,
VIR_FREE(actual); VIR_FREE(actual);
virNetworkDefFree(dev); virNetworkDefFree(dev);
virObjectUnref(xmlopt);
return ret; return ret;
} }

View File

@ -151,7 +151,7 @@ static int
test_virCapsDomainDataLookupQEMU(const void *data G_GNUC_UNUSED) test_virCapsDomainDataLookupQEMU(const void *data G_GNUC_UNUSED)
{ {
int ret = 0; int ret = 0;
virCaps *caps = NULL; g_autoptr(virCaps) caps = NULL;
if (!(caps = testQemuCapsInit())) { if (!(caps = testQemuCapsInit())) {
ret = -1; ret = -1;
@ -196,7 +196,6 @@ test_virCapsDomainDataLookupQEMU(const void *data G_GNUC_UNUSED)
CAPS_EXPECT_ERR(-1, VIR_ARCH_NONE, VIR_DOMAIN_VIRT_VMWARE, NULL, "pc"); CAPS_EXPECT_ERR(-1, VIR_ARCH_NONE, VIR_DOMAIN_VIRT_VMWARE, NULL, "pc");
out: out:
virObjectUnref(caps);
return ret; return ret;
} }
#endif /* WITH_QEMU */ #endif /* WITH_QEMU */
@ -206,7 +205,7 @@ static int
test_virCapsDomainDataLookupLXC(const void *data G_GNUC_UNUSED) test_virCapsDomainDataLookupLXC(const void *data G_GNUC_UNUSED)
{ {
int ret = 0; int ret = 0;
virCaps *caps = NULL; g_autoptr(virCaps) caps = NULL;
if (!(caps = testLXCCapsInit())) { if (!(caps = testLXCCapsInit())) {
ret = -1; ret = -1;
@ -221,7 +220,6 @@ test_virCapsDomainDataLookupLXC(const void *data G_GNUC_UNUSED)
VIR_DOMAIN_VIRT_LXC, "/usr/libexec/libvirt_lxc", NULL); VIR_DOMAIN_VIRT_LXC, "/usr/libexec/libvirt_lxc", NULL);
out: out:
virObjectUnref(caps);
return ret; return ret;
} }
#endif /* WITH_LXC */ #endif /* WITH_LXC */

View File

@ -35,7 +35,7 @@ static int
testMACLookup(const void *opaque) testMACLookup(const void *opaque)
{ {
const struct testData *data = opaque; const struct testData *data = opaque;
virMacMap *mgr = NULL; g_autoptr(virMacMap) mgr = NULL;
GSList *macs; GSList *macs;
GSList *next; GSList *next;
size_t i, j; size_t i, j;
@ -79,7 +79,6 @@ testMACLookup(const void *opaque)
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(file); VIR_FREE(file);
virObjectUnref(mgr);
return ret; return ret;
} }
@ -88,7 +87,7 @@ static int
testMACRemove(const void *opaque) testMACRemove(const void *opaque)
{ {
const struct testData *data = opaque; const struct testData *data = opaque;
virMacMap *mgr = NULL; g_autoptr(virMacMap) mgr = NULL;
GSList *macs; GSList *macs;
size_t i; size_t i;
char *file = NULL; char *file = NULL;
@ -117,7 +116,6 @@ testMACRemove(const void *opaque)
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(file); VIR_FREE(file);
virObjectUnref(mgr);
return ret; return ret;
} }

View File

@ -93,8 +93,8 @@ testVirPCIDeviceDetach(const void *opaque G_GNUC_UNUSED)
int ret = -1; int ret = -1;
virPCIDevice *dev[] = {NULL, NULL, NULL}; virPCIDevice *dev[] = {NULL, NULL, NULL};
size_t i, nDev = G_N_ELEMENTS(dev); size_t i, nDev = G_N_ELEMENTS(dev);
virPCIDeviceList *activeDevs = NULL; g_autoptr(virPCIDeviceList) activeDevs = NULL;
virPCIDeviceList *inactiveDevs = NULL; g_autoptr(virPCIDeviceList) inactiveDevs = NULL;
int count; int count;
if (!(activeDevs = virPCIDeviceListNew()) || if (!(activeDevs = virPCIDeviceListNew()) ||
@ -126,8 +126,6 @@ testVirPCIDeviceDetach(const void *opaque G_GNUC_UNUSED)
cleanup: cleanup:
for (i = 0; i < nDev; i++) for (i = 0; i < nDev; i++)
virPCIDeviceFree(dev[i]); virPCIDeviceFree(dev[i]);
virObjectUnref(activeDevs);
virObjectUnref(inactiveDevs);
return ret; return ret;
} }
@ -137,8 +135,8 @@ testVirPCIDeviceReset(const void *opaque G_GNUC_UNUSED)
int ret = -1; int ret = -1;
virPCIDevice *dev[] = {NULL, NULL, NULL}; virPCIDevice *dev[] = {NULL, NULL, NULL};
size_t i, nDev = G_N_ELEMENTS(dev); size_t i, nDev = G_N_ELEMENTS(dev);
virPCIDeviceList *activeDevs = NULL; g_autoptr(virPCIDeviceList) activeDevs = NULL;
virPCIDeviceList *inactiveDevs = NULL; g_autoptr(virPCIDeviceList) inactiveDevs = NULL;
int count; int count;
if (!(activeDevs = virPCIDeviceListNew()) || if (!(activeDevs = virPCIDeviceListNew()) ||
@ -164,8 +162,6 @@ testVirPCIDeviceReset(const void *opaque G_GNUC_UNUSED)
cleanup: cleanup:
for (i = 0; i < nDev; i++) for (i = 0; i < nDev; i++)
virPCIDeviceFree(dev[i]); virPCIDeviceFree(dev[i]);
virObjectUnref(activeDevs);
virObjectUnref(inactiveDevs);
return ret; return ret;
} }
@ -175,8 +171,8 @@ testVirPCIDeviceReattach(const void *opaque G_GNUC_UNUSED)
int ret = -1; int ret = -1;
virPCIDevice *dev[] = {NULL, NULL, NULL}; virPCIDevice *dev[] = {NULL, NULL, NULL};
size_t i, nDev = G_N_ELEMENTS(dev); size_t i, nDev = G_N_ELEMENTS(dev);
virPCIDeviceList *activeDevs = NULL; g_autoptr(virPCIDeviceList) activeDevs = NULL;
virPCIDeviceList *inactiveDevs = NULL; g_autoptr(virPCIDeviceList) inactiveDevs = NULL;
int count; int count;
if (!(activeDevs = virPCIDeviceListNew()) || if (!(activeDevs = virPCIDeviceListNew()) ||
@ -213,8 +209,6 @@ testVirPCIDeviceReattach(const void *opaque G_GNUC_UNUSED)
ret = 0; ret = 0;
cleanup: cleanup:
virObjectUnref(activeDevs);
virObjectUnref(inactiveDevs);
return ret; return ret;
} }

View File

@ -21,10 +21,10 @@ test_virResctrlGetUnused(const void *opaque)
char *system_dir = NULL; char *system_dir = NULL;
char *resctrl_dir = NULL; char *resctrl_dir = NULL;
int ret = -1; int ret = -1;
virResctrlAlloc *alloc = NULL; g_autoptr(virResctrlAlloc) alloc = NULL;
char *schemata_str = NULL; char *schemata_str = NULL;
char *schemata_file; char *schemata_file;
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,
data->filename); data->filename);
@ -65,8 +65,6 @@ test_virResctrlGetUnused(const void *opaque)
ret = 0; ret = 0;
cleanup: cleanup:
virObjectUnref(caps);
virObjectUnref(alloc);
VIR_FREE(system_dir); VIR_FREE(system_dir);
VIR_FREE(resctrl_dir); VIR_FREE(resctrl_dir);
VIR_FREE(schemata_str); VIR_FREE(schemata_str);

View File

@ -60,7 +60,7 @@ test1(const void *data G_GNUC_UNUSED)
static int static int
test2(const void *data G_GNUC_UNUSED) test2(const void *data G_GNUC_UNUSED)
{ {
virSCSIDeviceList *list = NULL; g_autoptr(virSCSIDeviceList) list = NULL;
virSCSIDevice *dev = NULL; virSCSIDevice *dev = NULL;
virSCSIDevice *dev1 = NULL; virSCSIDevice *dev1 = NULL;
bool free_dev = true; bool free_dev = true;
@ -157,7 +157,6 @@ test2(const void *data G_GNUC_UNUSED)
virSCSIDeviceFree(dev); virSCSIDeviceFree(dev);
if (free_dev1) if (free_dev1)
virSCSIDeviceFree(dev1); virSCSIDeviceFree(dev1);
virObjectUnref(list);
return ret; return ret;
} }

View File

@ -70,7 +70,7 @@ static int testDeviceFind(const void *opaque)
const struct findTestInfo *info = opaque; const struct findTestInfo *info = opaque;
int ret = -1; int ret = -1;
virUSBDevice *dev = NULL; virUSBDevice *dev = NULL;
virUSBDeviceList *devs = NULL; g_autoptr(virUSBDeviceList) devs = NULL;
int rv = 0; int rv = 0;
size_t i, ndevs = 0; size_t i, ndevs = 0;
@ -123,7 +123,6 @@ static int testDeviceFind(const void *opaque)
ret = 0; ret = 0;
cleanup: cleanup:
virObjectUnref(devs);
virUSBDeviceFree(dev); virUSBDeviceFree(dev);
return ret; return ret;
} }

View File

@ -67,7 +67,7 @@ testCompareParseXML(const char *xlcfg, const char *xml, bool replaceVars)
{ {
char *gotxlcfgData = NULL; char *gotxlcfgData = NULL;
g_autoptr(virConf) conf = NULL; g_autoptr(virConf) conf = NULL;
virConnectPtr conn = NULL; g_autoptr(virConnect) conn = NULL;
int wrote = 4096; int wrote = 4096;
int ret = -1; int ret = -1;
virDomainDef *def = NULL; virDomainDef *def = NULL;
@ -111,7 +111,6 @@ testCompareParseXML(const char *xlcfg, const char *xml, bool replaceVars)
VIR_FREE(replacedXML); VIR_FREE(replacedXML);
VIR_FREE(gotxlcfgData); VIR_FREE(gotxlcfgData);
virDomainDefFree(def); virDomainDefFree(def);
virObjectUnref(conn);
return ret; return ret;
} }
@ -127,7 +126,7 @@ testCompareFormatXML(const char *xlcfg, const char *xml, bool replaceVars)
char *gotxml = NULL; char *gotxml = NULL;
g_autoptr(virConf) conf = NULL; g_autoptr(virConf) conf = NULL;
int ret = -1; int ret = -1;
virConnectPtr conn; g_autoptr(virConnect) conn = NULL;
virDomainDef *def = NULL; virDomainDef *def = NULL;
char *replacedXML = NULL; char *replacedXML = NULL;
g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver); g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
@ -166,7 +165,6 @@ testCompareFormatXML(const char *xlcfg, const char *xml, bool replaceVars)
VIR_FREE(xlcfgData); VIR_FREE(xlcfgData);
VIR_FREE(gotxml); VIR_FREE(gotxml);
virDomainDefFree(def); virDomainDefFree(def);
virObjectUnref(conn);
return ret; return ret;
} }

View File

@ -42,7 +42,7 @@ testCompareParseXML(const char *xmcfg, const char *xml)
char *gotxmcfgData = NULL; char *gotxmcfgData = NULL;
g_autoptr(virConf) conf = NULL; g_autoptr(virConf) conf = NULL;
int ret = -1; int ret = -1;
virConnectPtr conn = NULL; g_autoptr(virConnect) conn = NULL;
int wrote = 4096; int wrote = 4096;
virDomainDef *def = NULL; virDomainDef *def = NULL;
@ -75,7 +75,6 @@ testCompareParseXML(const char *xmcfg, const char *xml)
fail: fail:
VIR_FREE(gotxmcfgData); VIR_FREE(gotxmcfgData);
virDomainDefFree(def); virDomainDefFree(def);
virObjectUnref(conn);
return ret; return ret;
} }