tests: use g_autoptr instead of virJSONValueFree

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
This commit is contained in:
Ján Tomko 2021-09-03 22:45:48 +02:00
parent 296f7173ed
commit 24b5739682
4 changed files with 7 additions and 14 deletions

View File

@ -87,7 +87,7 @@ qemuMonitorJSONIOProcessLine(qemuMonitor *mon,
const char *line, const char *line,
qemuMonitorMessage *msg) qemuMonitorMessage *msg)
{ {
virJSONValue *value = NULL; g_autoptr(virJSONValue) value = NULL;
g_autofree char *json = NULL; g_autofree char *json = NULL;
int ret; int ret;
@ -115,6 +115,5 @@ qemuMonitorJSONIOProcessLine(qemuMonitor *mon,
} }
cleanup: cleanup:
virJSONValueFree(value);
return ret; return ret;
} }

View File

@ -37,7 +37,7 @@ static int
testQemuCommandBuildFromJSON(const void *opaque) testQemuCommandBuildFromJSON(const void *opaque)
{ {
const testQemuCommandBuildObjectFromJSONData *data = opaque; const testQemuCommandBuildObjectFromJSONData *data = opaque;
virJSONValue *val = NULL; g_autoptr(virJSONValue) val = NULL;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER; g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
g_autofree char *result = NULL; g_autofree char *result = NULL;
int ret = -1; int ret = -1;
@ -65,7 +65,6 @@ testQemuCommandBuildFromJSON(const void *opaque)
ret = 0; ret = 0;
cleanup: cleanup:
virJSONValueFree(val);
return ret; return ret;
} }

View File

@ -2507,8 +2507,8 @@ testBlockNodeNameDetect(const void *opaque)
const char *pathprefix = "qemumonitorjsondata/qemumonitorjson-nodename-"; const char *pathprefix = "qemumonitorjsondata/qemumonitorjson-nodename-";
g_autofree char *resultFile = NULL; g_autofree char *resultFile = NULL;
g_autofree char *actual = NULL; g_autofree char *actual = NULL;
virJSONValue *namedNodesJson = NULL; g_autoptr(virJSONValue) namedNodesJson = NULL;
virJSONValue *blockstatsJson = NULL; g_autoptr(virJSONValue) blockstatsJson = NULL;
GHashTable *nodedata = NULL; GHashTable *nodedata = NULL;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER; g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
int ret = -1; int ret = -1;
@ -2541,8 +2541,6 @@ testBlockNodeNameDetect(const void *opaque)
cleanup: cleanup:
virHashFree(nodedata); virHashFree(nodedata);
virJSONValueFree(namedNodesJson);
virJSONValueFree(blockstatsJson);
return ret; return ret;
} }
@ -2584,7 +2582,7 @@ testQAPISchemaValidate(const void *opaque)
const struct testQAPISchemaData *data = opaque; const struct testQAPISchemaData *data = opaque;
g_auto(virBuffer) debug = VIR_BUFFER_INITIALIZER; g_auto(virBuffer) debug = VIR_BUFFER_INITIALIZER;
virJSONValue *schemaroot; virJSONValue *schemaroot;
virJSONValue *json = NULL; g_autoptr(virJSONValue) json = NULL;
int ret = -1; int ret = -1;
if (virQEMUQAPISchemaPathGet(data->query, data->schema, &schemaroot) < 0) if (virQEMUQAPISchemaPathGet(data->query, data->schema, &schemaroot) < 0)
@ -2610,7 +2608,6 @@ testQAPISchemaValidate(const void *opaque)
cleanup: cleanup:
virJSONValueFree(json);
return ret; return ret;
} }
@ -2927,7 +2924,7 @@ mymain(void)
virQEMUDriver driver; virQEMUDriver driver;
testQemuMonitorJSONSimpleFuncData simpleFunc; testQemuMonitorJSONSimpleFuncData simpleFunc;
struct testQAPISchemaData qapiData; struct testQAPISchemaData qapiData;
virJSONValue *metaschema = NULL; g_autoptr(virJSONValue) metaschema = NULL;
g_autofree char *metaschemastr = NULL; g_autofree char *metaschemastr = NULL;
if (qemuTestDriverInit(&driver) < 0) if (qemuTestDriverInit(&driver) < 0)
@ -3220,7 +3217,6 @@ mymain(void)
DO_TEST(qemuMonitorJSONGetCPUModelBaseline); DO_TEST(qemuMonitorJSONGetCPUModelBaseline);
cleanup: cleanup:
virJSONValueFree(metaschema);
virHashFree(qapiData.schema); virHashFree(qapiData.schema);
qemuTestDriverFree(&driver); qemuTestDriverFree(&driver);
return (ret == 0) ? EXIT_SUCCESS : EXIT_FAILURE; return (ret == 0) ? EXIT_SUCCESS : EXIT_FAILURE;

View File

@ -188,7 +188,7 @@ static char *testGenerateJSON(const char *server_name)
{ {
virNetDaemon *dmn = NULL; virNetDaemon *dmn = NULL;
virNetServer *srv = NULL; virNetServer *srv = NULL;
virJSONValue *json = NULL; g_autoptr(virJSONValue) json = NULL;
char *jsonstr = NULL; char *jsonstr = NULL;
bool has_ipv4, has_ipv6; bool has_ipv4, has_ipv6;
@ -226,7 +226,6 @@ static char *testGenerateJSON(const char *server_name)
virNetServerClose(srv); virNetServerClose(srv);
virObjectUnref(srv); virObjectUnref(srv);
virObjectUnref(dmn); virObjectUnref(dmn);
virJSONValueFree(json);
if (!jsonstr) if (!jsonstr)
virDispatchError(NULL); virDispatchError(NULL);
return jsonstr; return jsonstr;