]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
tests: vir: use g_autofree
authorJán Tomko <jtomko@redhat.com>
Sat, 4 Sep 2021 20:37:31 +0000 (22:37 +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>
24 files changed:
tests/vircgrouptest.c
tests/virconftest.c
tests/vircryptotest.c
tests/virfilecachetest.c
tests/virfilemock.c
tests/virfiletest.c
tests/virhostcputest.c
tests/viriscsitest.c
tests/virkmodtest.c
tests/virmacmaptest.c
tests/virnetdaemontest.c
tests/virnetsockettest.c
tests/virnetworkportxml2xmltest.c
tests/virnumamock.c
tests/virnwfilterbindingxml2xmltest.c
tests/virpcitest.c
tests/virresctrltest.c
tests/virscsitest.c
tests/virstringtest.c
tests/virsystemdtest.c
tests/virtestmock.c
tests/viruritest.c
tests/virusbmock.c
tests/virusbtest.c

index 1060f6073e71b306d7ea97d974f2b67d9425f390..7d54df1a853ae69d0759db8281eb040a87ab25b5 100644 (file)
@@ -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;
 }
 
index f1a58b01cffaac30c110997310265f2e5aebc75e..a7189579d3bd54f6b9d52404e7488493f362be22 100644 (file)
@@ -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;
 }
 
index 2c3d4bfe75d992baee3d98ae2160e2530b7d2e7e..2d503a439ee1158bc05049bcea9847d393bd560d 100644 (file)
@@ -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;
 }
index 3083aee35da270639596b00e88ff319028982326..5730e23b73bf4e76fe0ca7e88653e4ecd76a7649 100644 (file)
@@ -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;
 }
 
index bf153ab769329b1e67761c777cd73c6348792041..d4863bd12c01c58cea0b75c9c45c4b965af75c35 100644 (file)
@@ -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;
 }
 
index 3c1f2ce54efed5d1025992d2fb588e3c9bdebb74..019c230cea6cc6147298a30cf43589d7665e8323 100644 (file)
@@ -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
index 9e329b38b4eb35d65fc5fc4fbaa27281ee137d45..f935df0f6369c5c28336c077659788f4487857be 100644 (file)
@@ -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;
 }
 
index 37922ba55288e697a495da7d5a5731b8d52aa00f..7ea761fda6bf1f4915954b0de1c4941949b0d765 100644 (file)
@@ -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;
 }
 
index 2a85e0ae6d4c11cfc34b6b9ba2c4d893caf9454f..2f07757c8887bac5765457db628f6f49da943fd5 100644 (file)
@@ -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;
 }
 
index 4e7861502952c2305d81743796f4ab2a806a5d8a..01a3588ed9a8c75ecf451c673d6757d7dd45388f 100644 (file)
@@ -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;
 }
 
index f764268c501047e82aa8435ae5a8b50bee9f815a..2522a4c8ea82f8838e356cf0d5733fcb6216518d 100644 (file)
@@ -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);
index 1de3771ad4003df215ec358f32c85358dcd60784..d24baa9a5ce83064f6c7f0d9038891a1b75ed3c9 100644 (file)
@@ -178,7 +178,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 };
@@ -288,7 +288,6 @@ testSocketAccept(const void *opaque)
         virObjectUnref(lsock[i]);
     }
     VIR_FREE(lsock);
-    VIR_FREE(path);
     if (tmpdir)
         rmdir(tmpdir);
     return ret;
@@ -304,7 +303,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";
 
@@ -375,7 +374,6 @@ static int testSocketUNIXAddrs(const void *data G_GNUC_UNUSED)
     ret = 0;
 
  cleanup:
-    VIR_FREE(path);
     virObjectUnref(lsock);
     virObjectUnref(ssock);
     virObjectUnref(csock);
index 039da96490706bdfb779841076edad049fbcadef..8d29db724fc43f857f3b73b069f8ce06d32cbbf8 100644 (file)
@@ -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;
 }
 
index ff9c6e951d456074c14a8cafbab7b22d10cdf287..6e0293a49edf133404271fa827da9974b68c6081 100644 (file)
@@ -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;
 }
index ba8edcfd05bcd5fc70d3815b3c4aae9553a20789..ccdad3daa5363fa7a7751417a4849f27c12d1e95 100644 (file)
@@ -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;
 }
 
index 1cffe6e2795f2d5e3d265f1b6c671c3d760ce0bd..1ff0330b2245a252eae8c7209ca5531dbb65bb0d 100644 (file)
@@ -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;
 }
 
index b1dbf66d41684bba628849b0b26daa34972a1993..0beb9a4df455768b6341bf741e563b6ad543e542 100644 (file)
@@ -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;
 }
 
index 1b6a7b9ae94c278b37937bf3008167bc63eac8fb..d67cd238963b62f1f44e19103ebdfb169b9f80ca 100644 (file)
@@ -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;
 }
 
index 83b883524d1c245965b028b961f508602e6827b0..bbdd17da8428f2f8a068cf835048d4f9aa390df7 100644 (file)
@@ -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;
 }
 
index a09b428a8ae5ef781bdbe38944a592bc29d5b754..9cf6bfec43aa82b830e90e051cf32f775edbbff9 100644 (file)
@@ -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;
 }
 
index 0073677b4d8c70e77b3d0596d98c8246d69f8f0f..7951f3d00ff39eeda892201131e97bf08cf1ca40 100644 (file)
@@ -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;
 }
 
index 1962000bc8338a8238421bb061b655ed6eb5143b..96f29aafc08732590cc61dd0c11a1651ade6f375 100644 (file)
@@ -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;
 }
index 57c9611e5487f1c21761e33b69ef93d48d804332..a1f539b8b16149cd5c83d36455ba4de557b3d9b3 100644 (file)
@@ -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;
 }
index 39a8f1a18ebc58e4f27856e643d433bc190c9434..74333f01057366f3ddd3c48c1a2713e43852c281 100644 (file)
@@ -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;
 }