]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
tests: use g_autoptr instead of virObjectUnref
authorJán Tomko <jtomko@redhat.com>
Fri, 20 Aug 2021 13:53:53 +0000 (15:53 +0200)
committerJán Tomko <jtomko@redhat.com>
Thu, 9 Sep 2021 16:06:13 +0000 (18:06 +0200)
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
12 files changed:
tests/cputest.c
tests/domaincapstest.c
tests/networkxml2conftest.c
tests/networkxml2xmltest.c
tests/vircapstest.c
tests/virmacmaptest.c
tests/virpcitest.c
tests/virresctrltest.c
tests/virscsitest.c
tests/virusbtest.c
tests/xlconfigtest.c
tests/xmconfigtest.c

index 3e99b9486bd0e8506428636cd26bfa8618957add..11305d56c500aff75ddc0fe3a953be7f85b4a03e 100644 (file)
@@ -526,7 +526,7 @@ cpuTestCPUID(bool guest, const void *arg)
     g_autofree char *host = NULL;
     g_autoptr(virCPUDef) cpu = 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,
                                virArchToString(data->arch), data->host);
@@ -563,7 +563,6 @@ cpuTestCPUID(bool guest, const void *arg)
     ret = cpuTestCompareXML(data->arch, cpu, result);
 
  cleanup:
-    virObjectUnref(models);
     return ret;
 }
 
@@ -728,8 +727,8 @@ cpuTestUpdateLive(const void *arg)
     g_autoptr(virCPUData) disabledData = NULL;
     g_autofree char *expectedFile = NULL;
     g_autoptr(virCPUDef) expected = NULL;
-    virDomainCapsCPUModels *hvModels = NULL;
-    virDomainCapsCPUModels *models = NULL;
+    g_autoptr(virDomainCapsCPUModels) hvModels = NULL;
+    g_autoptr(virDomainCapsCPUModels) models = NULL;
     int ret = -1;
 
     cpuFile = g_strdup_printf("cpuid-%s-guest", data->host);
@@ -795,8 +794,6 @@ cpuTestUpdateLive(const void *arg)
     ret = cpuTestUpdateLiveCompare(data->arch, cpu, expected);
 
  cleanup:
-    virObjectUnref(hvModels);
-    virObjectUnref(models);
     return ret;
 }
 
index ca29644dee495e6e1e45df056dda7d8dc26ecc40..6ab14a01798c0c069c57c9faa4b0fb2a4a8e8aa7 100644 (file)
@@ -75,7 +75,7 @@ fillQemuCaps(virDomainCaps *domCaps,
 {
     int ret = -1;
     char *path = NULL;
-    virQEMUCaps *qemuCaps = NULL;
+    g_autoptr(virQEMUCaps) qemuCaps = NULL;
     virDomainCapsLoader *loader = &domCaps->os.loader;
     virDomainVirtType virtType;
 
@@ -127,7 +127,6 @@ fillQemuCaps(virDomainCaps *domCaps,
 
     ret = 0;
  cleanup:
-    virObjectUnref(qemuCaps);
     VIR_FREE(path);
     return ret;
 }
@@ -208,7 +207,7 @@ static int
 test_virDomainCapsFormat(const void *opaque)
 {
     const struct testData *data = opaque;
-    virDomainCaps *domCaps = NULL;
+    g_autoptr(virDomainCaps) domCaps = NULL;
     char *path = NULL;
     char *domCapsXML = NULL;
     int ret = -1;
@@ -256,7 +255,6 @@ test_virDomainCapsFormat(const void *opaque)
  cleanup:
     VIR_FREE(domCapsXML);
     VIR_FREE(path);
-    virObjectUnref(domCaps);
     return ret;
 }
 
index 7444390b77da95585b97a5b47ad402189114acce..a2ecc6e80af51b29a45bb4ed464cc9e2e3083893 100644 (file)
@@ -27,7 +27,7 @@ testCompareXMLToConfFiles(const char *inxml, const char *outconf,
     virCommand *cmd = NULL;
     char *pidfile = NULL;
     dnsmasqContext *dctx = NULL;
-    virNetworkXMLOption *xmlopt = NULL;
+    g_autoptr(virNetworkXMLOption) xmlopt = NULL;
 
     if (!(xmlopt = networkDnsmasqCreateXMLConf()))
         goto fail;
@@ -85,7 +85,6 @@ testCompareXMLToConfFiles(const char *inxml, const char *outconf,
     VIR_FREE(hostsfileactual);
     VIR_FREE(pidfile);
     virCommandFree(cmd);
-    virObjectUnref(xmlopt);
     virNetworkObjEndAPI(&obj);
     dnsmasqContextFree(dctx);
     return ret;
index 3b0a0b7c95d24be1db48fd51ba15c869c40ce41f..e1b5cdc7481b4c8d55bd3455197a064cd810527d 100644 (file)
@@ -30,7 +30,7 @@ testCompareXMLToXMLFiles(const char *inxml, const char *outxml,
     int ret;
     testCompareNetXML2XMLResult result = TEST_COMPARE_NET_XML2XML_RESULT_SUCCESS;
     virNetworkDef *dev = NULL;
-    virNetworkXMLOption *xmlopt = NULL;
+    g_autoptr(virNetworkXMLOption) xmlopt = NULL;
 
     if (!(xmlopt = networkDnsmasqCreateXMLConf()))
         goto cleanup;
@@ -72,7 +72,6 @@ testCompareXMLToXMLFiles(const char *inxml, const char *outxml,
 
     VIR_FREE(actual);
     virNetworkDefFree(dev);
-    virObjectUnref(xmlopt);
     return ret;
 }
 
index 7ec5b85222c56f4f95d504fe5351293a99dbbc41..ebabbbb9a09a721658fc1d5b8763999e3181f38a 100644 (file)
@@ -151,7 +151,7 @@ static int
 test_virCapsDomainDataLookupQEMU(const void *data G_GNUC_UNUSED)
 {
     int ret = 0;
-    virCaps *caps = NULL;
+    g_autoptr(virCaps) caps = NULL;
 
     if (!(caps = testQemuCapsInit())) {
         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");
 
  out:
-    virObjectUnref(caps);
     return ret;
 }
 #endif /* WITH_QEMU */
@@ -206,7 +205,7 @@ static int
 test_virCapsDomainDataLookupLXC(const void *data G_GNUC_UNUSED)
 {
     int ret = 0;
-    virCaps *caps = NULL;
+    g_autoptr(virCaps) caps = NULL;
 
     if (!(caps = testLXCCapsInit())) {
         ret = -1;
@@ -221,7 +220,6 @@ test_virCapsDomainDataLookupLXC(const void *data G_GNUC_UNUSED)
         VIR_DOMAIN_VIRT_LXC, "/usr/libexec/libvirt_lxc", NULL);
 
  out:
-    virObjectUnref(caps);
     return ret;
 }
 #endif /* WITH_LXC */
index 1b536af1ab1a24bfbd6f9f425c09121820b9bd29..4e7861502952c2305d81743796f4ab2a806a5d8a 100644 (file)
@@ -35,7 +35,7 @@ static int
 testMACLookup(const void *opaque)
 {
     const struct testData *data = opaque;
-    virMacMap *mgr = NULL;
+    g_autoptr(virMacMap) mgr = NULL;
     GSList *macs;
     GSList *next;
     size_t i, j;
@@ -79,7 +79,6 @@ testMACLookup(const void *opaque)
     ret = 0;
  cleanup:
     VIR_FREE(file);
-    virObjectUnref(mgr);
     return ret;
 }
 
@@ -88,7 +87,7 @@ static int
 testMACRemove(const void *opaque)
 {
     const struct testData *data = opaque;
-    virMacMap *mgr = NULL;
+    g_autoptr(virMacMap) mgr = NULL;
     GSList *macs;
     size_t i;
     char *file = NULL;
@@ -117,7 +116,6 @@ testMACRemove(const void *opaque)
     ret = 0;
  cleanup:
     VIR_FREE(file);
-    virObjectUnref(mgr);
     return ret;
 }
 
index 0466e5a0f75d9d6e16ea0ee0e87ff1f07fda7884..1cffe6e2795f2d5e3d265f1b6c671c3d760ce0bd 100644 (file)
@@ -93,8 +93,8 @@ testVirPCIDeviceDetach(const void *opaque G_GNUC_UNUSED)
     int ret = -1;
     virPCIDevice *dev[] = {NULL, NULL, NULL};
     size_t i, nDev = G_N_ELEMENTS(dev);
-    virPCIDeviceList *activeDevs = NULL;
-    virPCIDeviceList *inactiveDevs = NULL;
+    g_autoptr(virPCIDeviceList) activeDevs = NULL;
+    g_autoptr(virPCIDeviceList) inactiveDevs = NULL;
     int count;
 
     if (!(activeDevs = virPCIDeviceListNew()) ||
@@ -126,8 +126,6 @@ testVirPCIDeviceDetach(const void *opaque G_GNUC_UNUSED)
  cleanup:
     for (i = 0; i < nDev; i++)
         virPCIDeviceFree(dev[i]);
-    virObjectUnref(activeDevs);
-    virObjectUnref(inactiveDevs);
     return ret;
 }
 
@@ -137,8 +135,8 @@ testVirPCIDeviceReset(const void *opaque G_GNUC_UNUSED)
     int ret = -1;
     virPCIDevice *dev[] = {NULL, NULL, NULL};
     size_t i, nDev = G_N_ELEMENTS(dev);
-    virPCIDeviceList *activeDevs = NULL;
-    virPCIDeviceList *inactiveDevs = NULL;
+    g_autoptr(virPCIDeviceList) activeDevs = NULL;
+    g_autoptr(virPCIDeviceList) inactiveDevs = NULL;
     int count;
 
     if (!(activeDevs = virPCIDeviceListNew()) ||
@@ -164,8 +162,6 @@ testVirPCIDeviceReset(const void *opaque G_GNUC_UNUSED)
  cleanup:
     for (i = 0; i < nDev; i++)
         virPCIDeviceFree(dev[i]);
-    virObjectUnref(activeDevs);
-    virObjectUnref(inactiveDevs);
     return ret;
 }
 
@@ -175,8 +171,8 @@ testVirPCIDeviceReattach(const void *opaque G_GNUC_UNUSED)
     int ret = -1;
     virPCIDevice *dev[] = {NULL, NULL, NULL};
     size_t i, nDev = G_N_ELEMENTS(dev);
-    virPCIDeviceList *activeDevs = NULL;
-    virPCIDeviceList *inactiveDevs = NULL;
+    g_autoptr(virPCIDeviceList) activeDevs = NULL;
+    g_autoptr(virPCIDeviceList) inactiveDevs = NULL;
     int count;
 
     if (!(activeDevs = virPCIDeviceListNew()) ||
@@ -213,8 +209,6 @@ testVirPCIDeviceReattach(const void *opaque G_GNUC_UNUSED)
 
     ret = 0;
  cleanup:
-    virObjectUnref(activeDevs);
-    virObjectUnref(inactiveDevs);
     return ret;
 }
 
index 26fbde3668959c7a912453d482a64d91f3eda320..b1dbf66d41684bba628849b0b26daa34972a1993 100644 (file)
@@ -21,10 +21,10 @@ test_virResctrlGetUnused(const void *opaque)
     char *system_dir = NULL;
     char *resctrl_dir = NULL;
     int ret = -1;
-    virResctrlAlloc *alloc = NULL;
+    g_autoptr(virResctrlAlloc) alloc = NULL;
     char *schemata_str = NULL;
     char *schemata_file;
-    virCaps *caps = NULL;
+    g_autoptr(virCaps) caps = NULL;
 
     system_dir = g_strdup_printf("%s/vircaps2xmldata/linux-%s/system", abs_srcdir,
                                  data->filename);
@@ -65,8 +65,6 @@ test_virResctrlGetUnused(const void *opaque)
 
     ret = 0;
  cleanup:
-    virObjectUnref(caps);
-    virObjectUnref(alloc);
     VIR_FREE(system_dir);
     VIR_FREE(resctrl_dir);
     VIR_FREE(schemata_str);
index 0d7c35a2615cfd60aaa5166ecf3ece9e9186c410..1b6a7b9ae94c278b37937bf3008167bc63eac8fb 100644 (file)
@@ -60,7 +60,7 @@ test1(const void *data G_GNUC_UNUSED)
 static int
 test2(const void *data G_GNUC_UNUSED)
 {
-    virSCSIDeviceList *list = NULL;
+    g_autoptr(virSCSIDeviceList) list = NULL;
     virSCSIDevice *dev = NULL;
     virSCSIDevice *dev1 = NULL;
     bool free_dev = true;
@@ -157,7 +157,6 @@ test2(const void *data G_GNUC_UNUSED)
         virSCSIDeviceFree(dev);
     if (free_dev1)
         virSCSIDeviceFree(dev1);
-    virObjectUnref(list);
     return ret;
 }
 
index baad7dd821c0fd6c741ea0a7006cd1dc42baf1d4..39a8f1a18ebc58e4f27856e643d433bc190c9434 100644 (file)
@@ -70,7 +70,7 @@ static int testDeviceFind(const void *opaque)
     const struct findTestInfo *info = opaque;
     int ret = -1;
     virUSBDevice *dev = NULL;
-    virUSBDeviceList *devs = NULL;
+    g_autoptr(virUSBDeviceList) devs = NULL;
     int rv = 0;
     size_t i, ndevs = 0;
 
@@ -123,7 +123,6 @@ static int testDeviceFind(const void *opaque)
     ret = 0;
 
  cleanup:
-    virObjectUnref(devs);
     virUSBDeviceFree(dev);
     return ret;
 }
index e5c4a053bcb1e6dc6a3120dfa166cc6d998b4b30..0a2997b8b62ccbd94506e765f0390e76ce084afd 100644 (file)
@@ -67,7 +67,7 @@ testCompareParseXML(const char *xlcfg, const char *xml, bool replaceVars)
 {
     char *gotxlcfgData = NULL;
     g_autoptr(virConf) conf = NULL;
-    virConnectPtr conn = NULL;
+    g_autoptr(virConnect) conn = NULL;
     int wrote = 4096;
     int ret = -1;
     virDomainDef *def = NULL;
@@ -111,7 +111,6 @@ testCompareParseXML(const char *xlcfg, const char *xml, bool replaceVars)
     VIR_FREE(replacedXML);
     VIR_FREE(gotxlcfgData);
     virDomainDefFree(def);
-    virObjectUnref(conn);
 
     return ret;
 }
@@ -127,7 +126,7 @@ testCompareFormatXML(const char *xlcfg, const char *xml, bool replaceVars)
     char *gotxml = NULL;
     g_autoptr(virConf) conf = NULL;
     int ret = -1;
-    virConnectPtr conn;
+    g_autoptr(virConnect) conn = NULL;
     virDomainDef *def = NULL;
     char *replacedXML = NULL;
     g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
@@ -166,7 +165,6 @@ testCompareFormatXML(const char *xlcfg, const char *xml, bool replaceVars)
     VIR_FREE(xlcfgData);
     VIR_FREE(gotxml);
     virDomainDefFree(def);
-    virObjectUnref(conn);
 
     return ret;
 }
index bf74e4a1639b78de77722142e8a7776bfb3c3d9d..9d5eb85bf9e40af10eac9ab02ffc85a4888f0b9d 100644 (file)
@@ -42,7 +42,7 @@ testCompareParseXML(const char *xmcfg, const char *xml)
     char *gotxmcfgData = NULL;
     g_autoptr(virConf) conf = NULL;
     int ret = -1;
-    virConnectPtr conn = NULL;
+    g_autoptr(virConnect) conn = NULL;
     int wrote = 4096;
     virDomainDef *def = NULL;
 
@@ -75,7 +75,6 @@ testCompareParseXML(const char *xmcfg, const char *xml)
  fail:
     VIR_FREE(gotxmcfgData);
     virDomainDefFree(def);
-    virObjectUnref(conn);
 
     return ret;
 }