[libvirt PATCH 10/24] tests: vir: use g_autofree

Ján Tomko jtomko at redhat.com
Sat Sep 4 20:44:08 UTC 2021


Signed-off-by: Ján Tomko <jtomko at redhat.com>
---
 tests/vircgrouptest.c                 |  3 +--
 tests/virconftest.c                   |  6 ++----
 tests/vircryptotest.c                 | 12 ++++--------
 tests/virfilecachetest.c              |  3 +--
 tests/virfilemock.c                   |  3 +--
 tests/virfiletest.c                   |  6 ++----
 tests/virhostcputest.c                | 23 +++++++----------------
 tests/viriscsitest.c                  |  3 +--
 tests/virkmodtest.c                   |  9 +++------
 tests/virmacmaptest.c                 | 12 ++++--------
 tests/virnetdaemontest.c              | 12 ++++--------
 tests/virnetsockettest.c              |  6 ++----
 tests/virnetworkportxml2xmltest.c     |  8 ++------
 tests/virnumamock.c                   |  7 ++-----
 tests/virnwfilterbindingxml2xmltest.c |  7 ++-----
 tests/virpcitest.c                    | 16 +++++-----------
 tests/virresctrltest.c                | 12 ++++--------
 tests/virscsitest.c                   | 13 ++++---------
 tests/virstringtest.c                 | 12 ++++--------
 tests/virsystemdtest.c                |  9 +++------
 tests/virtestmock.c                   | 10 +++-------
 tests/viruritest.c                    |  3 +--
 tests/virusbmock.c                    |  7 ++-----
 tests/virusbtest.c                    |  3 +--
 24 files changed, 65 insertions(+), 140 deletions(-)

diff --git a/tests/vircgrouptest.c b/tests/vircgrouptest.c
index 1060f6073e..7d54df1a85 100644
--- a/tests/vircgrouptest.c
+++ b/tests/vircgrouptest.c
@@ -174,7 +174,7 @@ testCgroupDetectMounts(const void *args)
 {
     int result = -1;
     const struct _detectMountsData *data = args;
-    char *parsed = NULL;
+    g_autofree char *parsed = NULL;
     const char *actual;
     g_autoptr(virCgroup) group = NULL;
     g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
@@ -209,7 +209,6 @@ testCgroupDetectMounts(const void *args)
 
  cleanup:
     g_unsetenv("VIR_CGROUP_MOCK_FILENAME");
-    VIR_FREE(parsed);
     return result;
 }
 
diff --git a/tests/virconftest.c b/tests/virconftest.c
index f1a58b01cf..a7189579d3 100644
--- a/tests/virconftest.c
+++ b/tests/virconftest.c
@@ -70,7 +70,7 @@ static int testConfMemoryNoNewline(const void *opaque G_GNUC_UNUSED)
     int ret = -1;
     virConfValue *val;
     unsigned long long llvalue;
-    char *str = NULL;
+    g_autofree char *str = NULL;
     int uintvalue;
 
     if (!conf)
@@ -119,7 +119,6 @@ static int testConfMemoryNoNewline(const void *opaque G_GNUC_UNUSED)
 
     ret = 0;
  cleanup:
-    VIR_FREE(str);
     return ret;
 }
 
@@ -341,7 +340,7 @@ static int testConfParseString(const void *opaque G_GNUC_UNUSED)
 
     int ret = -1;
     g_autoptr(virConf) conf = virConfReadString(srcdata, 0);
-    char *str = NULL;
+    g_autofree char *str = NULL;
 
     if (!conf)
         return -1;
@@ -367,7 +366,6 @@ static int testConfParseString(const void *opaque G_GNUC_UNUSED)
 
     ret = 0;
  cleanup:
-    VIR_FREE(str);
     return ret;
 }
 
diff --git a/tests/vircryptotest.c b/tests/vircryptotest.c
index 2c3d4bfe75..2d503a439e 100644
--- a/tests/vircryptotest.c
+++ b/tests/vircryptotest.c
@@ -37,7 +37,7 @@ static int
 testCryptoHash(const void *opaque)
 {
     const struct testCryptoHashData *data = opaque;
-    char *actual = NULL;
+    g_autofree char *actual = NULL;
     int ret = -1;
 
     if (virCryptoHashString(data->hash, data->input, &actual) < 0) {
@@ -53,7 +53,6 @@ testCryptoHash(const void *opaque)
 
     ret = 0;
  cleanup:
-    VIR_FREE(actual);
     return ret;
 }
 
@@ -70,11 +69,11 @@ static int
 testCryptoEncrypt(const void *opaque)
 {
     const struct testCryptoEncryptData *data = opaque;
-    uint8_t *enckey = NULL;
+    g_autofree uint8_t *enckey = NULL;
     size_t enckeylen = 32;
-    uint8_t *iv = NULL;
+    g_autofree uint8_t *iv = NULL;
     size_t ivlen = 16;
-    uint8_t *ciphertext = NULL;
+    g_autofree uint8_t *ciphertext = NULL;
     size_t ciphertextlen = 0;
     int ret = -1;
 
@@ -110,9 +109,6 @@ testCryptoEncrypt(const void *opaque)
 
     ret = 0;
  cleanup:
-    VIR_FREE(enckey);
-    VIR_FREE(iv);
-    VIR_FREE(ciphertext);
 
     return ret;
 }
diff --git a/tests/virfilecachetest.c b/tests/virfilecachetest.c
index 3083aee35d..5730e23b73 100644
--- a/tests/virfilecachetest.c
+++ b/tests/virfilecachetest.c
@@ -112,14 +112,13 @@ testFileCacheLoadFile(const char *filename,
                       bool *outdated G_GNUC_UNUSED)
 {
     testFileCacheObj *obj;
-    char *data;
+    g_autofree char *data = NULL;
 
     if (virFileReadAll(filename, 20, &data) < 0)
         return NULL;
 
     obj = testFileCacheObjNew(data);
 
-    VIR_FREE(data);
     return obj;
 }
 
diff --git a/tests/virfilemock.c b/tests/virfilemock.c
index bf153ab769..d4863bd12c 100644
--- a/tests/virfilemock.c
+++ b/tests/virfilemock.c
@@ -105,7 +105,7 @@ statfs_mock(const char *mtab,
     FILE *f;
     struct mntent mb;
     char mntbuf[1024];
-    char *canonPath = NULL;
+    g_autofree char *canonPath = NULL;
     int ret = -1;
 
     if (!(f = real_setmntent(mtab, "r"))) {
@@ -158,7 +158,6 @@ statfs_mock(const char *mtab,
     }
 
     endmntent(f);
-    VIR_FREE(canonPath);
     return ret;
 }
 
diff --git a/tests/virfiletest.c b/tests/virfiletest.c
index 3c1f2ce54e..019c230cea 100644
--- a/tests/virfiletest.c
+++ b/tests/virfiletest.c
@@ -104,7 +104,7 @@ testFileSanitizePath(const void *opaque)
 {
     const struct testFileSanitizePathData *data = opaque;
     int ret = -1;
-    char *actual;
+    g_autofree char *actual = NULL;
 
     if (!(actual = virFileSanitizePath(data->path)))
         return -1;
@@ -117,7 +117,6 @@ testFileSanitizePath(const void *opaque)
     ret = 0;
 
  cleanup:
-    VIR_FREE(actual);
     return ret;
 }
 
@@ -322,7 +321,7 @@ testFileIsSharedFSType(const void *opaque G_GNUC_UNUSED)
     return EXIT_AM_SKIP;
 #else
     const struct testFileIsSharedFSType *data = opaque;
-    char *mtabFile = NULL;
+    g_autofree char *mtabFile = NULL;
     bool actual;
     int ret = -1;
 
@@ -343,7 +342,6 @@ testFileIsSharedFSType(const void *opaque G_GNUC_UNUSED)
 
     ret = 0;
  cleanup:
-    VIR_FREE(mtabFile);
     g_unsetenv("LIBVIRT_MTAB");
     return ret;
 #endif
diff --git a/tests/virhostcputest.c b/tests/virhostcputest.c
index 9e329b38b4..f935df0f63 100644
--- a/tests/virhostcputest.c
+++ b/tests/virhostcputest.c
@@ -31,7 +31,7 @@ linuxTestCompareFiles(const char *cpuinfofile,
                       const char *outputfile)
 {
     int ret = -1;
-    char *actualData = NULL;
+    g_autofree char *actualData = NULL;
     virNodeInfo nodeinfo;
     FILE *cpuinfo;
 
@@ -68,7 +68,6 @@ linuxTestCompareFiles(const char *cpuinfofile,
     ret = 0;
 
  fail:
-    VIR_FREE(actualData);
     return ret;
 }
 
@@ -109,7 +108,7 @@ linuxCPUStatsCompareFiles(const char *cpustatfile,
                           const char *outfile)
 {
     int ret = -1;
-    char *actualData = NULL;
+    g_autofree char *actualData = NULL;
     FILE *cpustat = NULL;
     virNodeCPUStatsPtr params = NULL;
     g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
@@ -150,7 +149,6 @@ linuxCPUStatsCompareFiles(const char *cpustatfile,
 
  fail:
     VIR_FORCE_FCLOSE(cpustat);
-    VIR_FREE(actualData);
     VIR_FREE(params);
     return ret;
 }
@@ -165,9 +163,9 @@ static int
 linuxTestHostCPU(const void *opaque)
 {
     int result = -1;
-    char *cpuinfo = NULL;
-    char *sysfs_prefix = NULL;
-    char *output = NULL;
+    g_autofree char *cpuinfo = NULL;
+    g_autofree char *sysfs_prefix = NULL;
+    g_autofree char *output = NULL;
     struct linuxTestHostCPUData *data = (struct linuxTestHostCPUData *) opaque;
     const char *archStr = virArchToString(data->arch);
 
@@ -182,10 +180,6 @@ linuxTestHostCPU(const void *opaque)
     result = linuxTestCompareFiles(cpuinfo, data->arch, output);
     virFileWrapperRemovePrefix(SYSFS_SYSTEM_PATH);
 
-    VIR_FREE(cpuinfo);
-    VIR_FREE(output);
-    VIR_FREE(sysfs_prefix);
-
     return result;
 }
 
@@ -232,8 +226,8 @@ linuxTestNodeCPUStats(const void *data)
 {
     const struct nodeCPUStatsData *testData = data;
     int result = -1;
-    char *cpustatfile = NULL;
-    char *outfile = NULL;
+    g_autofree char *cpustatfile = NULL;
+    g_autofree g_autofree char *outfile = NULL;
 
     cpustatfile = g_strdup_printf("%s/virhostcpudata/linux-cpustat-%s.stat",
                                   abs_srcdir, testData->name);
@@ -255,9 +249,6 @@ linuxTestNodeCPUStats(const void *data)
         }
     }
 
-
-    VIR_FREE(cpustatfile);
-    VIR_FREE(outfile);
     return result;
 }
 
diff --git a/tests/viriscsitest.c b/tests/viriscsitest.c
index 37922ba552..7ea761fda6 100644
--- a/tests/viriscsitest.c
+++ b/tests/viriscsitest.c
@@ -210,7 +210,7 @@ testISCSIGetSession(const void *data)
 {
     const struct testSessionInfo *info = data;
     struct testIscsiadmCbData cbData = { 0 };
-    char *actual_session = NULL;
+    g_autofree char *actual_session = NULL;
     int ret = -1;
     g_autoptr(virCommandDryRunToken) dryRunToken = virCommandDryRunTokenNew();
 
@@ -231,7 +231,6 @@ testISCSIGetSession(const void *data)
     ret = 0;
 
  cleanup:
-    VIR_FREE(actual_session);
     return ret;
 }
 
diff --git a/tests/virkmodtest.c b/tests/virkmodtest.c
index 2a85e0ae6d..2f07757c88 100644
--- a/tests/virkmodtest.c
+++ b/tests/virkmodtest.c
@@ -35,7 +35,7 @@ static int
 checkOutput(virBuffer *buf, const char *exp_cmd)
 {
     int ret = -1;
-    char *actual_cmd = NULL;
+    g_autofree char *actual_cmd = NULL;
 
     if (!(actual_cmd = virBufferContentAndReset(buf))) {
         fprintf(stderr, "cannot compare buffer to exp: %s", exp_cmd);
@@ -50,7 +50,6 @@ checkOutput(virBuffer *buf, const char *exp_cmd)
     ret = 0;
 
  cleanup:
-    VIR_FREE(actual_cmd);
     return ret;
 }
 
@@ -59,7 +58,7 @@ static int
 testKModLoad(const void *args G_GNUC_UNUSED)
 {
     int ret = -1;
-    char *errbuf = NULL;
+    g_autofree char *errbuf = NULL;
     g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
     g_autoptr(virCommandDryRunToken) dryRunToken = virCommandDryRunTokenNew();
 
@@ -77,7 +76,6 @@ testKModLoad(const void *args G_GNUC_UNUSED)
     ret = 0;
 
  cleanup:
-    VIR_FREE(errbuf);
     return ret;
 }
 
@@ -86,7 +84,7 @@ static int
 testKModUnload(const void *args G_GNUC_UNUSED)
 {
     int ret = -1;
-    char *errbuf = NULL;
+    g_autofree char *errbuf = NULL;
     g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
     g_autoptr(virCommandDryRunToken) dryRunToken = virCommandDryRunTokenNew();
 
@@ -104,7 +102,6 @@ testKModUnload(const void *args G_GNUC_UNUSED)
     ret = 0;
 
  cleanup:
-    VIR_FREE(errbuf);
     return ret;
 }
 
diff --git a/tests/virmacmaptest.c b/tests/virmacmaptest.c
index 4e78615029..01a3588ed9 100644
--- a/tests/virmacmaptest.c
+++ b/tests/virmacmaptest.c
@@ -39,7 +39,7 @@ testMACLookup(const void *opaque)
     GSList *macs;
     GSList *next;
     size_t i, j;
-    char *file = NULL;
+    g_autofree char *file = NULL;
     int ret = -1;
 
     file = g_strdup_printf("%s/virmacmaptestdata/%s.json", abs_srcdir, data->file);
@@ -78,7 +78,6 @@ testMACLookup(const void *opaque)
 
     ret = 0;
  cleanup:
-    VIR_FREE(file);
     return ret;
 }
 
@@ -90,7 +89,7 @@ testMACRemove(const void *opaque)
     g_autoptr(virMacMap) mgr = NULL;
     GSList *macs;
     size_t i;
-    char *file = NULL;
+    g_autofree char *file = NULL;
     int ret = -1;
 
     file = g_strdup_printf("%s/virmacmaptestdata/%s.json", abs_srcdir, data->file);
@@ -115,7 +114,6 @@ testMACRemove(const void *opaque)
 
     ret = 0;
  cleanup:
-    VIR_FREE(file);
     return ret;
 }
 
@@ -124,8 +122,8 @@ static int
 testMACFlush(const void *opaque)
 {
     const struct testData *data = opaque;
-    char *file = NULL;
-    char *str = NULL;
+    g_autofree char *file = NULL;
+    g_autofree char *str = NULL;
     int ret = -1;
 
     file = g_strdup_printf("%s/virmacmaptestdata/%s.json", abs_srcdir, data->file);
@@ -138,8 +136,6 @@ testMACFlush(const void *opaque)
 
     ret = 0;
  cleanup:
-    VIR_FREE(file);
-    VIR_FREE(str);
     return ret;
 }
 
diff --git a/tests/virnetdaemontest.c b/tests/virnetdaemontest.c
index f764268c50..2522a4c8ea 100644
--- a/tests/virnetdaemontest.c
+++ b/tests/virnetdaemontest.c
@@ -270,10 +270,10 @@ static int testExecRestart(const void *opaque)
     int ret = -1;
     virNetDaemon *dmn = NULL;
     const struct testExecRestartData *data = opaque;
-    char *infile = NULL;
-    char *outfile = NULL;
-    char *injsonstr = NULL;
-    char *outjsonstr = NULL;
+    g_autofree char *infile = NULL;
+    g_autofree char *outfile = NULL;
+    g_autofree char *injsonstr = NULL;
+    g_autofree char *outjsonstr = NULL;
     virJSONValue *injson = NULL;
     virJSONValue *outjson = NULL;
     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");
             ret = -1;
     }
-    VIR_FREE(infile);
-    VIR_FREE(outfile);
-    VIR_FREE(injsonstr);
-    VIR_FREE(outjsonstr);
     virJSONValueFree(injson);
     virJSONValueFree(outjson);
     virObjectUnref(dmn);
diff --git a/tests/virnetsockettest.c b/tests/virnetsockettest.c
index 8059c6cbb0..8fbbea5d30 100644
--- a/tests/virnetsockettest.c
+++ b/tests/virnetsockettest.c
@@ -186,7 +186,7 @@ testSocketAccept(const void *opaque)
     int ret = -1;
     char portstr[100];
     char *tmpdir = NULL;
-    char *path = NULL;
+    g_autofree char *path = NULL;
     char template[] = "/tmp/libvirt_XXXXXX";
     virThread th;
     struct testClientData cdata = { 0 };
@@ -296,7 +296,6 @@ testSocketAccept(const void *opaque)
         virObjectUnref(lsock[i]);
     }
     VIR_FREE(lsock);
-    VIR_FREE(path);
     if (tmpdir)
         rmdir(tmpdir);
     return ret;
@@ -312,7 +311,7 @@ static int testSocketUNIXAddrs(const void *data G_GNUC_UNUSED)
     virNetSocket *csock = NULL; /* Client socket */
     int ret = -1;
 
-    char *path = NULL;
+    g_autofree char *path = NULL;
     char *tmpdir;
     char template[] = "/tmp/libvirt_XXXXXX";
 
@@ -383,7 +382,6 @@ static int testSocketUNIXAddrs(const void *data G_GNUC_UNUSED)
     ret = 0;
 
  cleanup:
-    VIR_FREE(path);
     virObjectUnref(lsock);
     virObjectUnref(ssock);
     virObjectUnref(csock);
diff --git a/tests/virnetworkportxml2xmltest.c b/tests/virnetworkportxml2xmltest.c
index 039da96490..8d29db724f 100644
--- a/tests/virnetworkportxml2xmltest.c
+++ b/tests/virnetworkportxml2xmltest.c
@@ -36,7 +36,7 @@
 static int
 testCompareXMLToXMLFiles(const char *expected)
 {
-    char *actual = NULL;
+    g_autofree char *actual = NULL;
     int ret = -1;
     g_autoptr(virNetworkPortDef) dev = NULL;
 
@@ -51,7 +51,6 @@ testCompareXMLToXMLFiles(const char *expected)
 
     ret = 0;
  cleanup:
-    VIR_FREE(actual);
     return ret;
 }
 
@@ -64,15 +63,12 @@ testCompareXMLToXMLHelper(const void *data)
 {
     const struct testInfo *info = data;
     int ret = -1;
-    char *xml = NULL;
+    g_autofree char *xml = NULL;
 
     xml = g_strdup_printf("%s/virnetworkportxml2xmldata/%s.xml", abs_srcdir,
                           info->name);
 
     ret = testCompareXMLToXMLFiles(xml);
-
-    VIR_FREE(xml);
-
     return ret;
 }
 
diff --git a/tests/virnumamock.c b/tests/virnumamock.c
index ff9c6e951d..6e0293a49e 100644
--- a/tests/virnumamock.c
+++ b/tests/virnumamock.c
@@ -41,13 +41,11 @@ bool
 virNumaIsAvailable(void)
 {
     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);
 
         numa_avail = virFileExists(sysfs_node_path);
-
-        VIR_FREE(sysfs_node_path);
     }
 
     /*
@@ -165,7 +163,7 @@ int
 virNumaGetNodeCPUs(int node, virBitmap **cpus)
 {
     int ret = -1;
-    char *cpulist = NULL;
+    g_autofree char *cpulist = NULL;
 
     if (virFileReadValueString(&cpulist,
                                "%s/node/node%u/cpulist",
@@ -183,6 +181,5 @@ virNumaGetNodeCPUs(int node, virBitmap **cpus)
 
     ret = virBitmapCountBits(*cpus);
  cleanup:
-    VIR_FREE(cpulist);
     return ret;
 }
diff --git a/tests/virnwfilterbindingxml2xmltest.c b/tests/virnwfilterbindingxml2xmltest.c
index ba8edcfd05..ccdad3daa5 100644
--- a/tests/virnwfilterbindingxml2xmltest.c
+++ b/tests/virnwfilterbindingxml2xmltest.c
@@ -38,7 +38,7 @@
 static int
 testCompareXMLToXMLFiles(const char *xml)
 {
-    char *actual = NULL;
+    g_autofree char *actual = NULL;
     int ret = -1;
     virNWFilterBindingDef *dev = NULL;
 
@@ -56,7 +56,6 @@ testCompareXMLToXMLFiles(const char *xml)
     ret = 0;
 
  fail:
-    VIR_FREE(actual);
     virNWFilterBindingDefFree(dev);
     return ret;
 }
@@ -70,15 +69,13 @@ testCompareXMLToXMLHelper(const void *data)
 {
     int result = -1;
     const test_parms *tp = data;
-    char *xml = NULL;
+    g_autofree char *xml = NULL;
 
     xml = g_strdup_printf("%s/virnwfilterbindingxml2xmldata/%s.xml", abs_srcdir,
                           tp->name);
 
     result = testCompareXMLToXMLFiles(xml);
 
-    VIR_FREE(xml);
-
     return result;
 }
 
diff --git a/tests/virpcitest.c b/tests/virpcitest.c
index 1cffe6e279..1ff0330b22 100644
--- a/tests/virpcitest.c
+++ b/tests/virpcitest.c
@@ -32,8 +32,8 @@
 static int
 testVirPCIDeviceCheckDriver(virPCIDevice *dev, const char *expected)
 {
-    char *path = NULL;
-    char *driver = NULL;
+    g_autofree char *path = NULL;
+    g_autofree char *driver = NULL;
     int ret = -1;
 
     if (virPCIDeviceGetDriverPathAndName(dev, &path, &driver) < 0)
@@ -49,8 +49,6 @@ testVirPCIDeviceCheckDriver(virPCIDevice *dev, const char *expected)
 
     ret = 0;
  cleanup:
-    VIR_FREE(path);
-    VIR_FREE(driver);
     return ret;
 }
 
@@ -339,7 +337,7 @@ static int
 mymain(void)
 {
     int ret = 0;
-    char *fakerootdir;
+    g_autofree char *fakerootdir = NULL;
 
     fakerootdir = g_strdup(FAKEROOTDIRTEMPLATE);
 
@@ -361,12 +359,11 @@ mymain(void)
         struct testPCIDevData data = { \
             domain, bus, slot, function, NULL \
         }; \
-        char *label = NULL; \
+        g_autofree char *label = NULL; \
         label = g_strdup_printf("%s(%04x:%02x:%02x.%x)", \
                                 #fnc, domain, bus, slot, function); \
         if (virTestRun(label, fnc, &data) < 0) \
             ret = -1; \
-        VIR_FREE(label); \
     } while (0)
 
 # define DO_TEST_PCI_DRIVER(domain, bus, slot, function, driver) \
@@ -374,14 +371,13 @@ mymain(void)
         struct testPCIDevData data = { \
             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", \
                                 domain, bus, slot, function, \
                                 NULLSTR(driver)); \
         if (virTestRun(label, testVirPCIDeviceCheckDriverTest, \
                        &data) < 0) \
             ret = -1; \
-        VIR_FREE(label); \
     } while (0)
 
     /* Changes made to individual devices are persistent and the
@@ -419,8 +415,6 @@ mymain(void)
     if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL)
         virFileDeleteTree(fakerootdir);
 
-    VIR_FREE(fakerootdir);
-
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }
 
diff --git a/tests/virresctrltest.c b/tests/virresctrltest.c
index b1dbf66d41..0beb9a4df4 100644
--- a/tests/virresctrltest.c
+++ b/tests/virresctrltest.c
@@ -18,12 +18,12 @@ static int
 test_virResctrlGetUnused(const void *opaque)
 {
     struct virResctrlData *data = (struct virResctrlData *) opaque;
-    char *system_dir = NULL;
-    char *resctrl_dir = NULL;
+    g_autofree char *system_dir = NULL;
+    g_autofree char *resctrl_dir = NULL;
     int ret = -1;
     g_autoptr(virResctrlAlloc) alloc = NULL;
-    char *schemata_str = NULL;
-    char *schemata_file;
+    g_autofree char *schemata_str = NULL;
+    g_autofree char *schemata_file = NULL;
     g_autoptr(virCaps) caps = NULL;
 
     system_dir = g_strdup_printf("%s/vircaps2xmldata/linux-%s/system", abs_srcdir,
@@ -65,10 +65,6 @@ test_virResctrlGetUnused(const void *opaque)
 
     ret = 0;
  cleanup:
-    VIR_FREE(system_dir);
-    VIR_FREE(resctrl_dir);
-    VIR_FREE(schemata_str);
-    VIR_FREE(schemata_file);
     return ret;
 }
 
diff --git a/tests/virscsitest.c b/tests/virscsitest.c
index 1b6a7b9ae9..d67cd23896 100644
--- a/tests/virscsitest.c
+++ b/tests/virscsitest.c
@@ -36,7 +36,7 @@ static char *virscsi_prefix;
 static int
 test1(const void *data G_GNUC_UNUSED)
 {
-    char *name = NULL;
+    g_autofree char *name = NULL;
     int ret = -1;
 
     if (!(name = virSCSIDeviceGetDevName(virscsi_prefix,
@@ -48,7 +48,6 @@ test1(const void *data G_GNUC_UNUSED)
 
     ret = 0;
  cleanup:
-    VIR_FREE(name);
     return ret;
 }
 
@@ -66,7 +65,7 @@ test2(const void *data G_GNUC_UNUSED)
     bool free_dev = true;
     bool free_dev1 = true;
     virSCSIDevice *tmp = NULL;
-    char *sgname = NULL;
+    g_autofree char *sgname = NULL;
     int ret = -1;
 
     sgname = virSCSIDeviceGetSgName(virscsi_prefix,
@@ -152,7 +151,6 @@ test2(const void *data G_GNUC_UNUSED)
 
     ret = 0;
  cleanup:
-    VIR_FREE(sgname);
     if (free_dev)
         virSCSIDeviceFree(dev);
     if (free_dev1)
@@ -164,8 +162,8 @@ static int
 create_symlink(const char *tmpdir, const char *src_name, const char *dst_name)
 {
     int ret = -1;
-    char *src_path = NULL;
-    char *dst_path = NULL;
+    g_autofree char *src_path = NULL;
+    g_autofree char *dst_path = NULL;
 
     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;
 
  cleanup:
-    VIR_FREE(src_path);
-    VIR_FREE(dst_path);
-
     return ret;
 }
 
diff --git a/tests/virstringtest.c b/tests/virstringtest.c
index 83b883524d..bbdd17da84 100644
--- a/tests/virstringtest.c
+++ b/tests/virstringtest.c
@@ -222,7 +222,7 @@ static int
 testStringReplace(const void *opaque G_GNUC_UNUSED)
 {
     const struct stringReplaceData *data = opaque;
-    char *result;
+    g_autofree char *result = NULL;
     int ret = -1;
 
     result = virStringReplace(data->haystack,
@@ -238,7 +238,6 @@ testStringReplace(const void *opaque G_GNUC_UNUSED)
     ret = 0;
 
  cleanup:
-    VIR_FREE(result);
     return ret;
 }
 
@@ -402,7 +401,7 @@ static int testStripIPv6Brackets(const void *args)
 {
     const struct testStripData *data = args;
     int ret = -1;
-    char *res = NULL;
+    g_autofree char *res = NULL;
 
     res = g_strdup(data->string);
 
@@ -417,7 +416,6 @@ static int testStripIPv6Brackets(const void *args)
     ret = 0;
 
  cleanup:
-    VIR_FREE(res);
     return ret;
 }
 
@@ -425,7 +423,7 @@ static int testStripControlChars(const void *args)
 {
     const struct testStripData *data = args;
     int ret = -1;
-    char *res = NULL;
+    g_autofree char *res = NULL;
 
     res = g_strdup(data->string);
 
@@ -440,7 +438,6 @@ static int testStripControlChars(const void *args)
     ret = 0;
 
  cleanup:
-    VIR_FREE(res);
     return ret;
 }
 
@@ -454,7 +451,7 @@ static int testFilterChars(const void *args)
 {
     const struct testFilterData *data = args;
     int ret = -1;
-    char *res = NULL;
+    g_autofree char *res = NULL;
 
     res = g_strdup(data->string);
 
@@ -469,7 +466,6 @@ static int testFilterChars(const void *args)
     ret = 0;
 
  cleanup:
-    VIR_FREE(res);
     return ret;
 }
 
diff --git a/tests/virsystemdtest.c b/tests/virsystemdtest.c
index a09b428a8a..9cf6bfec43 100644
--- a/tests/virsystemdtest.c
+++ b/tests/virsystemdtest.c
@@ -325,7 +325,7 @@ static int testCreateNetwork(const void *opaque G_GNUC_UNUSED)
 static int
 testGetMachineName(const void *opaque G_GNUC_UNUSED)
 {
-    char *tmp = virSystemdGetMachineNameByPID(1234);
+    g_autofree char *tmp = virSystemdGetMachineNameByPID(1234);
     int ret = -1;
 
     if (!tmp) {
@@ -336,7 +336,6 @@ testGetMachineName(const void *opaque G_GNUC_UNUSED)
     if (STREQ(tmp, "qemu-demo"))
         ret = 0;
 
-    VIR_FREE(tmp);
     return ret;
 }
 
@@ -371,7 +370,7 @@ testScopeName(const void *opaque)
 {
     const struct testNameData *data = opaque;
     int ret = -1;
-    char *actual = NULL;
+    g_autofree char *actual = NULL;
 
     if (!(actual = virSystemdMakeScopeName(data->name, "lxc", data->legacy)))
         goto cleanup;
@@ -385,7 +384,6 @@ testScopeName(const void *opaque)
     ret = 0;
 
  cleanup:
-    VIR_FREE(actual);
     return ret;
 }
 
@@ -394,7 +392,7 @@ testMachineName(const void *opaque)
 {
     const struct testNameData *data = opaque;
     int ret = -1;
-    char *actual = NULL;
+    g_autofree char *actual = NULL;
 
     if (!(actual = virDomainDriverGenerateMachineName("qemu", data->root,
                                                       data->id, data->name, true)))
@@ -409,7 +407,6 @@ testMachineName(const void *opaque)
     ret = 0;
 
  cleanup:
-    VIR_FREE(actual);
     return ret;
 }
 
diff --git a/tests/virtestmock.c b/tests/virtestmock.c
index 0073677b4d..7951f3d00f 100644
--- a/tests/virtestmock.c
+++ b/tests/virtestmock.c
@@ -100,9 +100,9 @@ static void
 checkPath(const char *path,
           const char *func)
 {
-    char *fullPath = NULL;
-    char *relPath = NULL;
-    char *crippledPath = NULL;
+    g_autofree char *fullPath = NULL;
+    g_autofree char *relPath = NULL;
+    g_autofree char *crippledPath = NULL;
 
     if (!g_path_is_absolute(path))
         relPath = g_strdup_printf("./%s", path);
@@ -130,10 +130,6 @@ checkPath(const char *path,
         printFile(path, func);
     }
 
-    VIR_FREE(crippledPath);
-    VIR_FREE(relPath);
-    VIR_FREE(fullPath);
-
     return;
 }
 
diff --git a/tests/viruritest.c b/tests/viruritest.c
index 1962000bc8..96f29aafc0 100644
--- a/tests/viruritest.c
+++ b/tests/viruritest.c
@@ -49,7 +49,7 @@ static int testURIParse(const void *args)
     int ret = -1;
     virURI *uri = NULL;
     const struct URIParseData *data = args;
-    char *uristr = NULL;
+    g_autofree char *uristr = NULL;
     size_t i;
     bool fail = false;
 
@@ -134,7 +134,6 @@ static int testURIParse(const void *args)
 
     ret = 0;
  cleanup:
-    VIR_FREE(uristr);
     virURIFree(uri);
     return ret;
 }
diff --git a/tests/virusbmock.c b/tests/virusbmock.c
index 57c9611e54..a1f539b8b1 100644
--- a/tests/virusbmock.c
+++ b/tests/virusbmock.c
@@ -63,7 +63,7 @@ static char *get_fake_path(const char *real_path)
 
 DIR *opendir(const char *name)
 {
-    char *path;
+    g_autofree char *path = NULL;
     DIR* ret;
 
     init_syms();
@@ -71,13 +71,12 @@ DIR *opendir(const char *name)
     path = get_fake_path(name);
 
     ret = realopendir(path);
-    VIR_FREE(path);
     return ret;
 }
 
 int open(const char *pathname, int flags, ...)
 {
-    char *path;
+    g_autofree char *path = NULL;
     int ret;
     va_list ap;
     mode_t mode = 0;
@@ -98,7 +97,5 @@ int open(const char *pathname, int flags, ...)
     }
 
     ret = realopen(path, flags, mode);
-
-    VIR_FREE(path);
     return ret;
 }
diff --git a/tests/virusbtest.c b/tests/virusbtest.c
index 39a8f1a18e..74333f0105 100644
--- a/tests/virusbtest.c
+++ b/tests/virusbtest.c
@@ -49,7 +49,7 @@ static int testDeviceFileActor(virUSBDevice *dev,
                                const char *path,
                                void *opaque G_GNUC_UNUSED)
 {
-    char *str = NULL;
+    g_autofree char *str = NULL;
     int ret = 0;
 
     str = g_strdup_printf(USB_DEVFS "%03d/%03d", virUSBDeviceGetBus(dev),
@@ -61,7 +61,6 @@ static int testDeviceFileActor(virUSBDevice *dev,
                        path, str);
         ret = -1;
     }
-    VIR_FREE(str);
     return ret;
 }
 
-- 
2.31.1




More information about the libvir-list mailing list