[libvirt PATCH 05/24] tests: qemu: use g_autofree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Ján Tomko <jtomko@xxxxxxxxxx>
---
 tests/qemucapsprobemock.c   |  6 ++---
 tests/qemucommandutiltest.c |  3 +--
 tests/qemumonitorjsontest.c | 48 +++++++++++++------------------------
 tests/qemuxml2argvtest.c    |  3 +--
 4 files changed, 20 insertions(+), 40 deletions(-)

diff --git a/tests/qemucapsprobemock.c b/tests/qemucapsprobemock.c
index 3c05a80ca2..00670101ce 100644
--- a/tests/qemucapsprobemock.c
+++ b/tests/qemucapsprobemock.c
@@ -58,7 +58,7 @@ int
 qemuMonitorSend(qemuMonitor *mon,
                 qemuMonitorMessage *msg)
 {
-    char *reformatted;
+    g_autofree char *reformatted = NULL;
 
     REAL_SYM(realQemuMonitorSend);
 
@@ -73,7 +73,6 @@ qemuMonitorSend(qemuMonitor *mon,
         printLineSkipEmpty("\n", stdout);
 
     printLineSkipEmpty(reformatted, stdout);
-    VIR_FREE(reformatted);
 
     return realQemuMonitorSend(mon, msg);
 }
@@ -89,7 +88,7 @@ qemuMonitorJSONIOProcessLine(qemuMonitor *mon,
                              qemuMonitorMessage *msg)
 {
     virJSONValue *value = NULL;
-    char *json = NULL;
+    g_autofree char *json = NULL;
     int ret;
 
     REAL_SYM(realQemuMonitorJSONIOProcessLine);
@@ -116,7 +115,6 @@ qemuMonitorJSONIOProcessLine(qemuMonitor *mon,
     }
 
  cleanup:
-    VIR_FREE(json);
     virJSONValueFree(value);
     return ret;
 }
diff --git a/tests/qemucommandutiltest.c b/tests/qemucommandutiltest.c
index 33f92d2935..6b5e477849 100644
--- a/tests/qemucommandutiltest.c
+++ b/tests/qemucommandutiltest.c
@@ -39,7 +39,7 @@ testQemuCommandBuildFromJSON(const void *opaque)
     const testQemuCommandBuildObjectFromJSONData *data = opaque;
     virJSONValue *val = NULL;
     g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
-    char *result = NULL;
+    g_autofree char *result = NULL;
     int ret = -1;
 
     if (!(val = virJSONValueFromString(data->props))) {
@@ -66,7 +66,6 @@ testQemuCommandBuildFromJSON(const void *opaque)
     ret = 0;
  cleanup:
     virJSONValueFree(val);
-    VIR_FREE(result);
     return ret;
 }
 
diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c
index 9ec5f06981..c64c5c6b6f 100644
--- a/tests/qemumonitorjsontest.c
+++ b/tests/qemumonitorjsontest.c
@@ -650,8 +650,8 @@ qemuMonitorJSONTestAttachOneChardev(virDomainXMLOption *xmlopt,
 
 {
     struct qemuMonitorJSONTestAttachChardevData data = {0};
-    char *jsonreply = NULL;
-    char *fulllabel = NULL;
+    g_autofree char *jsonreply = NULL;
+    g_autofree char *fulllabel = NULL;
     int ret = -1;
 
     if (!reply)
@@ -680,8 +680,6 @@ qemuMonitorJSONTestAttachOneChardev(virDomainXMLOption *xmlopt,
 
  cleanup:
     qemuMonitorTestFree(data.test);
-    VIR_FREE(jsonreply);
-    VIR_FREE(fulllabel);
     return ret;
 }
 
@@ -1723,7 +1721,7 @@ testQemuMonitorJSONqemuMonitorJSONGetMigrationStats(const void *opaque)
     virDomainXMLOption *xmlopt = data->xmlopt;
     int ret = -1;
     qemuMonitorMigrationStats stats, expectedStats;
-    char *error = NULL;
+    g_autofree char *error = NULL;
     g_autoptr(qemuMonitorTest) test = NULL;
 
     if (!(test = qemuMonitorTestNewSchema(xmlopt, data->schema)))
@@ -1784,7 +1782,6 @@ testQemuMonitorJSONqemuMonitorJSONGetMigrationStats(const void *opaque)
 
     ret = 0;
  cleanup:
-    VIR_FREE(error);
     return ret;
 }
 
@@ -2162,10 +2159,10 @@ testQemuMonitorJSONGetCPUData(const void *opaque)
 {
     const struct testCPUData *data = opaque;
     virCPUData *cpuData = NULL;
-    char *jsonFile = NULL;
-    char *dataFile = NULL;
-    char *jsonStr = NULL;
-    char *actual = NULL;
+    g_autofree char *jsonFile = NULL;
+    g_autofree char *dataFile = NULL;
+    g_autofree char *jsonStr = NULL;
+    g_autofree char *actual = NULL;
     int ret = -1;
     g_autoptr(qemuMonitorTest) test = NULL;
 
@@ -2211,10 +2208,6 @@ testQemuMonitorJSONGetCPUData(const void *opaque)
 
     ret = 0;
  cleanup:
-    VIR_FREE(jsonFile);
-    VIR_FREE(dataFile);
-    VIR_FREE(jsonStr);
-    VIR_FREE(actual);
     virCPUDataFree(cpuData);
     return ret;
 }
@@ -2409,12 +2402,12 @@ testQemuMonitorCPUInfo(const void *opaque)
 {
     const struct testCPUInfoData *data = opaque;
     virDomainObj *vm = NULL;
-    char *queryCpusFile = NULL;
-    char *queryHotpluggableFile = NULL;
-    char *dataFile = NULL;
-    char *queryCpusStr = NULL;
-    char *queryHotpluggableStr = NULL;
-    char *actual = NULL;
+    g_autofree char *queryCpusFile = NULL;
+    g_autofree char *queryHotpluggableFile = NULL;
+    g_autofree char *dataFile = NULL;
+    g_autofree char *queryCpusStr = NULL;
+    g_autofree char *queryHotpluggableStr = NULL;
+    g_autofree char *actual = NULL;
     const char *queryCpusFunction;
     qemuMonitorCPUInfo *vcpus = NULL;
     int rc;
@@ -2468,12 +2461,6 @@ testQemuMonitorCPUInfo(const void *opaque)
 
     ret = 0;
  cleanup:
-    VIR_FREE(queryCpusFile);
-    VIR_FREE(queryHotpluggableFile);
-    VIR_FREE(dataFile);
-    VIR_FREE(queryCpusStr);
-    VIR_FREE(queryHotpluggableStr);
-    VIR_FREE(actual);
     qemuMonitorCPUInfoFree(vcpus, data->maxvcpus);
     return ret;
 }
@@ -2518,8 +2505,8 @@ testBlockNodeNameDetect(const void *opaque)
 {
     const char *testname = opaque;
     const char *pathprefix = "qemumonitorjsondata/qemumonitorjson-nodename-";
-    char *resultFile = NULL;
-    char *actual = NULL;
+    g_autofree char *resultFile = NULL;
+    g_autofree char *actual = NULL;
     virJSONValue *namedNodesJson = NULL;
     virJSONValue *blockstatsJson = NULL;
     GHashTable *nodedata = NULL;
@@ -2553,8 +2540,6 @@ testBlockNodeNameDetect(const void *opaque)
     ret = 0;
 
  cleanup:
-    VIR_FREE(resultFile);
-    VIR_FREE(actual);
     virHashFree(nodedata);
     virJSONValueFree(namedNodesJson);
     virJSONValueFree(blockstatsJson);
@@ -2943,7 +2928,7 @@ mymain(void)
     testQemuMonitorJSONSimpleFuncData simpleFunc;
     struct testQAPISchemaData qapiData;
     virJSONValue *metaschema = NULL;
-    char *metaschemastr = NULL;
+    g_autofree char *metaschemastr = NULL;
 
     if (qemuTestDriverInit(&driver) < 0)
         return EXIT_FAILURE;
@@ -3235,7 +3220,6 @@ mymain(void)
     DO_TEST(qemuMonitorJSONGetCPUModelBaseline);
 
  cleanup:
-    VIR_FREE(metaschemastr);
     virJSONValueFree(metaschema);
     virHashFree(qapiData.schema);
     qemuTestDriverFree(&driver);
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 3b331d5fd4..90b7da8055 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -643,7 +643,7 @@ testCompareXMLToArgv(const void *data)
     virDomainChrSourceDef monitor_chr;
     g_autoptr(virConnect) conn = NULL;
     virError *err = NULL;
-    char *log = NULL;
+    g_autofree char *log = NULL;
     g_autoptr(virCommand) cmd = NULL;
     qemuDomainObjPrivate *priv = NULL;
     g_autoptr(xmlDoc) xml = NULL;
@@ -815,7 +815,6 @@ testCompareXMLToArgv(const void *data)
     ret = 0;
 
  cleanup:
-    VIR_FREE(log);
     virDomainChrSourceDefClear(&monitor_chr);
     virObjectUnref(vm);
     virIdentitySetCurrent(NULL);
-- 
2.31.1




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux