[libvirt PATCH 12/24] tests: use g_autoptr instead of virJSONValueFree

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


Signed-off-by: Ján Tomko <jtomko at redhat.com>
---
 tests/qemucapsprobemock.c   |  3 +--
 tests/qemucommandutiltest.c |  3 +--
 tests/qemumonitorjsontest.c | 12 ++++--------
 tests/virnetdaemontest.c    |  3 +--
 4 files changed, 7 insertions(+), 14 deletions(-)

diff --git a/tests/qemucapsprobemock.c b/tests/qemucapsprobemock.c
index 00670101ce..27539d04a1 100644
--- a/tests/qemucapsprobemock.c
+++ b/tests/qemucapsprobemock.c
@@ -87,7 +87,7 @@ qemuMonitorJSONIOProcessLine(qemuMonitor *mon,
                              const char *line,
                              qemuMonitorMessage *msg)
 {
-    virJSONValue *value = NULL;
+    g_autoptr(virJSONValue) value = NULL;
     g_autofree char *json = NULL;
     int ret;
 
@@ -115,6 +115,5 @@ qemuMonitorJSONIOProcessLine(qemuMonitor *mon,
     }
 
  cleanup:
-    virJSONValueFree(value);
     return ret;
 }
diff --git a/tests/qemucommandutiltest.c b/tests/qemucommandutiltest.c
index 6b5e477849..e1cab0be90 100644
--- a/tests/qemucommandutiltest.c
+++ b/tests/qemucommandutiltest.c
@@ -37,7 +37,7 @@ static int
 testQemuCommandBuildFromJSON(const void *opaque)
 {
     const testQemuCommandBuildObjectFromJSONData *data = opaque;
-    virJSONValue *val = NULL;
+    g_autoptr(virJSONValue) val = NULL;
     g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
     g_autofree char *result = NULL;
     int ret = -1;
@@ -65,7 +65,6 @@ testQemuCommandBuildFromJSON(const void *opaque)
 
     ret = 0;
  cleanup:
-    virJSONValueFree(val);
     return ret;
 }
 
diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c
index c64c5c6b6f..542b35850e 100644
--- a/tests/qemumonitorjsontest.c
+++ b/tests/qemumonitorjsontest.c
@@ -2507,8 +2507,8 @@ testBlockNodeNameDetect(const void *opaque)
     const char *pathprefix = "qemumonitorjsondata/qemumonitorjson-nodename-";
     g_autofree char *resultFile = NULL;
     g_autofree char *actual = NULL;
-    virJSONValue *namedNodesJson = NULL;
-    virJSONValue *blockstatsJson = NULL;
+    g_autoptr(virJSONValue) namedNodesJson = NULL;
+    g_autoptr(virJSONValue) blockstatsJson = NULL;
     GHashTable *nodedata = NULL;
     g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
     int ret = -1;
@@ -2541,8 +2541,6 @@ testBlockNodeNameDetect(const void *opaque)
 
  cleanup:
     virHashFree(nodedata);
-    virJSONValueFree(namedNodesJson);
-    virJSONValueFree(blockstatsJson);
 
     return ret;
 }
@@ -2584,7 +2582,7 @@ testQAPISchemaValidate(const void *opaque)
     const struct testQAPISchemaData *data = opaque;
     g_auto(virBuffer) debug = VIR_BUFFER_INITIALIZER;
     virJSONValue *schemaroot;
-    virJSONValue *json = NULL;
+    g_autoptr(virJSONValue) json = NULL;
     int ret = -1;
 
     if (virQEMUQAPISchemaPathGet(data->query, data->schema, &schemaroot) < 0)
@@ -2610,7 +2608,6 @@ testQAPISchemaValidate(const void *opaque)
 
 
  cleanup:
-    virJSONValueFree(json);
     return ret;
 }
 
@@ -2927,7 +2924,7 @@ mymain(void)
     virQEMUDriver driver;
     testQemuMonitorJSONSimpleFuncData simpleFunc;
     struct testQAPISchemaData qapiData;
-    virJSONValue *metaschema = NULL;
+    g_autoptr(virJSONValue) metaschema = NULL;
     g_autofree char *metaschemastr = NULL;
 
     if (qemuTestDriverInit(&driver) < 0)
@@ -3220,7 +3217,6 @@ mymain(void)
     DO_TEST(qemuMonitorJSONGetCPUModelBaseline);
 
  cleanup:
-    virJSONValueFree(metaschema);
     virHashFree(qapiData.schema);
     qemuTestDriverFree(&driver);
     return (ret == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
diff --git a/tests/virnetdaemontest.c b/tests/virnetdaemontest.c
index 2522a4c8ea..70af1480df 100644
--- a/tests/virnetdaemontest.c
+++ b/tests/virnetdaemontest.c
@@ -188,7 +188,7 @@ static char *testGenerateJSON(const char *server_name)
 {
     virNetDaemon *dmn = NULL;
     virNetServer *srv = NULL;
-    virJSONValue *json = NULL;
+    g_autoptr(virJSONValue) json = NULL;
     char *jsonstr = NULL;
     bool has_ipv4, has_ipv6;
 
@@ -226,7 +226,6 @@ static char *testGenerateJSON(const char *server_name)
     virNetServerClose(srv);
     virObjectUnref(srv);
     virObjectUnref(dmn);
-    virJSONValueFree(json);
     if (!jsonstr)
         virDispatchError(NULL);
     return jsonstr;
-- 
2.31.1




More information about the libvir-list mailing list