Fix some memory leaks in test-visitor-serialization
PATCH v2 1/1 Fix some memory leaks in test-visitor-serialization
This patch fixes some of the memory leaks in test-visitor-serialization but not all of them.
---
v1->v2: call qobject_decref(obj) earlier
--- tests/test-visitor-serialization.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
tests/test-visitor-serialization.c +1 -0
@@ -258,6 +258,7 @@ static void test_primitives(gconstpointeg_assert (pt_copy !=NULL );if (pt->type ==PTYPE_STRING ) { g_assert_cmpstr(pt->value.string, ==, pt_copy->value.string); +g_free ((char *)pt_copy->value.string); }else if (pt->type ==PTYPE_NUMBER ) {/* we serialize with %f for our reference visitors, so rather
than fuzzy
* floating math to test "equality", just compare the
formatted values
@@ -275,6 +276,7 @@ static void test_primitives(gconstpointe
ops->cleanup(serialize_data);
g_free(args);+ g_free(pt_copy);
}
static void test_struct(gconstpointer opaque)
@@ -660,6 +662,7 @@ static void qmp_deserialize(void **nativ
QDECREF(output_json);
d->qiv = qmp_input_visitor_new(obj);
+ qobject_decref(obj);
visit(qmp_input_get_visitor(d->qiv), native_out, errp);}
@@ -668,9 +671,12 @@ static void qmp_cleanup(void *datap)
QmpSerializeData *d = datap;
qmp_output_visitor_cleanup(d->qov);
qmp_input_visitor_cleanup(d->qiv);+
+ g_free(d);
}
typedef struct StringSerializeData {
+ char *string;
StringOutputVisitor *sov;
StringInputVisitor *siv;
} StringSerializeData;
@@ -690,15 +696,19 @@ static void string_deserialize(void **na
{
StringSerializeData *d = datap;- d->siv = string_input_visitor_new(string_output_get_string(d->sov));
+ d->string = string_output_get_string(d->sov);
+ d->siv = string_input_visitor_new(d->string);
visit(string_input_get_visitor(d->siv), native_out, errp);}
static void string_cleanup(void *datap)
{
StringSerializeData *d = datap;
+
string_output_visitor_cleanup(d->sov);
string_input_visitor_cleanup(d->siv);+ g_free(d->string);
+ g_free(d);
}
/* visitor registration, test harness */
Quoted 23 lines · Stefan Berger
This patch fixes some of the memory leaks in
test-visitor-serialization but not all of them.Signed-off-by Stefan Berger <[email protected]>---
v1->v2: callqobject_decref(obj)earlier--- tests/test-visitor-serialization.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)Index:
qemu-git.pt/tests/test-visitor-serialization.c
===================================================================tests/test-visitor-serialization.c +1
-0@@ -258,6 +258,7 @@ static void test_primitives(gconstpointeg_assert (pt_copy !=NULL );if (pt->type ==PTYPE_STRING ) { g_assert_cmpstr(pt->value.string, ==, pt_copy->value.string); +g_free ((char *)pt_copy->value.string); }else if (pt->type ==PTYPE_NUMBER ) {/* we serialize with %f for our reference visitors, so
Quoted 3 lines
rather than fuzzy
* floating math to test "equality", just compare the
formatted values
The patch is line-wrapped. Please fix your mail client configuration, git-am(1) refuses to apply automatically.
Thanks,
Stefan
PATCH v2 1/1 Fix some memory leaks in test-visitor-serialization
This patch fixes some of the memory leaks in test-visitor-serialization but not all of them.
--- tests/test-visitor-serialization.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
tests/test-visitor-serialization.c +1 -0
@@ -258,6 +258,7 @@ static void test_primitives(gconstpointeg_assert (pt_copy !=NULL );if (pt->type ==PTYPE_STRING ) { g_assert_cmpstr(pt->value.string, ==, pt_copy->value.string); +g_free ((char *)pt_copy->value.string); }else if (pt->type ==PTYPE_NUMBER ) {/* we serialize with %f for our reference visitors, so rather
than fuzzy
* floating math to test "equality", just compare the
formatted values
@@ -275,6 +276,7 @@ static void test_primitives(gconstpointe
ops->cleanup(serialize_data);
g_free(args);+ g_free(pt_copy);
}
static void test_struct(gconstpointer opaque)
@@ -660,6 +662,7 @@ static void qmp_deserialize(void **nativ
QDECREF(output_json);
d->qiv = qmp_input_visitor_new(obj);
+ qobject_decref(obj);
visit(qmp_input_get_visitor(d->qiv), native_out, errp);}
@@ -668,9 +671,12 @@ static void qmp_cleanup(void *datap)
QmpSerializeData *d = datap;
qmp_output_visitor_cleanup(d->qov);
qmp_input_visitor_cleanup(d->qiv);+
+ g_free(d);
}
typedef struct StringSerializeData {
+ char *string;
StringOutputVisitor *sov;
StringInputVisitor *siv;
} StringSerializeData;
@@ -690,15 +696,19 @@ static void string_deserialize(void **na
{
StringSerializeData *d = datap;- d->siv = string_input_visitor_new(string_output_get_string(d->sov));
+ d->string = string_output_get_string(d->sov);
+ d->siv = string_input_visitor_new(d->string);
visit(string_input_get_visitor(d->siv), native_out, errp);}
static void string_cleanup(void *datap)
{
StringSerializeData *d = datap;
+
string_output_visitor_cleanup(d->sov);
string_input_visitor_cleanup(d->siv);+ g_free(d->string);
+ g_free(d);
}
/* visitor registration, test harness */