Skip to contentSkip to conversation

test-keyval: fix leaks

PATCH Applied Marc-André Lureau 4 participants 5 messages Apr 10, 2017 – Apr 12, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 test-keyval: fix leaks

---
 tests/test-keyval.c | 4 ++++
 1 file changed, 4 insertions(+)
tests/test-keyval.c +4 -0
index ba19560a22..141ee5d0c4 100644
@@ -628,6 +628,7 @@ static void test_keyval_visit_alternate(void)
     visit_type_AltNumStr(v, "a", &ans, &error_abort);
     g_assert_cmpint(ans->type, ==, QTYPE_QSTRING);
     g_assert_cmpstr(ans->u.s, ==, "1");
+    qapi_free_AltNumStr(ans);
     visit_type_AltNumInt(v, "a", &ani, &err);
     error_free_or_abort(&err);
     visit_end_struct(v, NULL);
@@ -649,11 +650,14 @@ static void test_keyval_visit_any(void)
     visit_type_any(v, "a", &any, &error_abort);
     qlist = qobject_to_qlist(any);
     g_assert(qlist);
+    qobject_decref(any);
     qstr = qobject_to_qstring(qlist_pop(qlist));
     g_assert_cmpstr(qstring_get_str(qstr), ==, "null");
+    QDECREF(qstr);
     qstr = qobject_to_qstring(qlist_pop(qlist));
     g_assert_cmpstr(qstring_get_str(qstr), ==, "1");
     g_assert(qlist_empty(qlist));
+    QDECREF(qstr);
     visit_check_struct(v, &error_abort);
     visit_end_struct(v, NULL);
     visit_free(v);
Signature · 1 line
2.12.0.191.gc5d8de91d
Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · Marc-André Lureau
---
 tests/test-keyval.c | 4 ++++
 1 file changed, 4 insertions(+)

Leaks in the testsuite are not showstoppers, so I'm okay if we defer it to 2.10 to minimize churn now that we are late in hard freeze.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
Reviewed-by on v1 1/1
#2 lore raw
In reply to Marc-André Lureau
Quoted 18 lines · Marc-André Lureau
---
 tests/test-keyval.c | 4 ++++
 1 file changed, 4 insertions(+)
tests/test-keyval.c +1 -0
index ba19560a22..141ee5d0c4 100644
@@ -628,6 +628,7 @@ static void test_keyval_visit_alternate(void)
     visit_type_AltNumStr(v, "a", &ans, &error_abort);
     g_assert_cmpint(ans->type, ==, QTYPE_QSTRING);
     g_assert_cmpstr(ans->u.s, ==, "1");
+    qapi_free_AltNumStr(ans);
     visit_type_AltNumInt(v, "a", &ani, &err);
     error_free_or_abort(&err);
     visit_end_struct(v, NULL);

tests/test-keyval.c static void test_keyval_visit_any(void) · line 650

Quoted 1 line
tests/test-keyval.c +0 -0
@@ -649,11 +650,14 @@ static void test_keyval_visit_any(void)
     visit_type_any(v, "a", &any, &error_abort);

@any becomes a strong reference (qobject_input_type_any() increments the reference count).

tests/test-keyval.c static void test_keyval_visit_any(void) · line 651

Quoted 1 line
tests/test-keyval.c +0 -0
     qlist = qobject_to_qlist(any);

Reference count unchanged.

tests/test-keyval.c static void test_keyval_visit_any(void) · line 653

Quoted 2 lines
tests/test-keyval.c +1 -0
     g_assert(qlist);
+    qobject_decref(any);

Uh, this is unnecessarily dirty: you relinquish the reference before you're actually done with it. Works only because there's *another* reference hiding within @v. Let's move this ...

tests/test-keyval.c static void test_keyval_visit_any(void) · line 660

Quoted 7 lines
tests/test-keyval.c +2 -0
     qstr = qobject_to_qstring(qlist_pop(qlist));
     g_assert_cmpstr(qstring_get_str(qstr), ==, "null");
+    QDECREF(qstr);
     qstr = qobject_to_qstring(qlist_pop(qlist));
     g_assert_cmpstr(qstring_get_str(qstr), ==, "1");
     g_assert(qlist_empty(qlist));
+    QDECREF(qstr);

... here. Okay to do that on commit?

tests/test-keyval.c static void test_keyval_visit_any(void) · line 663

Quoted 3 lines
tests/test-keyval.c +0 -0
     visit_check_struct(v, &error_abort);
     visit_end_struct(v, NULL);
     visit_free(v);

With the reference counting cleaned up:

#3 lore raw

Hi

Quoted 44 lines · Markus Armbruster
Quoted 18 lines · Marc-André Lureau
---
 tests/test-keyval.c | 4 ++++
 1 file changed, 4 insertions(+)
tests/test-keyval.c +1 -0
index ba19560a22..141ee5d0c4 100644
@@ -628,6 +628,7 @@ static void test_keyval_visit_alternate(void)
     visit_type_AltNumStr(v, "a", &ans, &error_abort);
     g_assert_cmpint(ans->type, ==, QTYPE_QSTRING);
     g_assert_cmpstr(ans->u.s, ==, "1");
+    qapi_free_AltNumStr(ans);
     visit_type_AltNumInt(v, "a", &ani, &err);
     error_free_or_abort(&err);
     visit_end_struct(v, NULL);

tests/test-keyval.c static void test_keyval_visit_any(void) · line 650

Quoted 1 line
tests/test-keyval.c +0 -0
@@ -649,11 +650,14 @@ static void test_keyval_visit_any(void)
     visit_type_any(v, "a", &any, &error_abort);

@any becomes a strong reference (qobject_input_type_any() increments the reference count).

tests/test-keyval.c static void test_keyval_visit_any(void) · line 651

Quoted 1 line
tests/test-keyval.c +0 -0
     qlist = qobject_to_qlist(any);

Reference count unchanged.

tests/test-keyval.c static void test_keyval_visit_any(void) · line 653

Quoted 2 lines
tests/test-keyval.c +1 -0
     g_assert(qlist);
+    qobject_decref(any);

Uh, this is unnecessarily dirty: you relinquish the reference before you're actually done with it. Works only because there's *another* reference hiding within @v. Let's move this ...

tests/test-keyval.c static void test_keyval_visit_any(void) · line 660

Quoted 7 lines
tests/test-keyval.c +2 -0
     qstr = qobject_to_qstring(qlist_pop(qlist));
     g_assert_cmpstr(qstring_get_str(qstr), ==, "null");
+    QDECREF(qstr);
     qstr = qobject_to_qstring(qlist_pop(qlist));
     g_assert_cmpstr(qstring_get_str(qstr), ==, "1");
     g_assert(qlist_empty(qlist));
+    QDECREF(qstr);
Quoted 2 lines

... here. Okay to do that on commit?

sure, makes sense

Quoted 8 lines

tests/test-keyval.c static void test_keyval_visit_any(void) · line 663

Quoted 3 lines
tests/test-keyval.c +0 -0
     visit_check_struct(v, &error_abort);
     visit_end_struct(v, NULL);
     visit_free(v);

With the reference counting cleaned up:

thanks

Signature · 1 line
Marc-André Lureau
#4 lore raw
Quoted 58 lines · Marc-André Lureau

Hi

Quoted 44 lines · Markus Armbruster
Quoted 18 lines · Marc-André Lureau
---
 tests/test-keyval.c | 4 ++++
 1 file changed, 4 insertions(+)
tests/test-keyval.c +1 -0
index ba19560a22..141ee5d0c4 100644
@@ -628,6 +628,7 @@ static void test_keyval_visit_alternate(void)
     visit_type_AltNumStr(v, "a", &ans, &error_abort);
     g_assert_cmpint(ans->type, ==, QTYPE_QSTRING);
     g_assert_cmpstr(ans->u.s, ==, "1");
+    qapi_free_AltNumStr(ans);
     visit_type_AltNumInt(v, "a", &ani, &err);
     error_free_or_abort(&err);
     visit_end_struct(v, NULL);

tests/test-keyval.c static void test_keyval_visit_any(void) · line 650

Quoted 1 line
tests/test-keyval.c +0 -0
@@ -649,11 +650,14 @@ static void test_keyval_visit_any(void)
     visit_type_any(v, "a", &any, &error_abort);

@any becomes a strong reference (qobject_input_type_any() increments the reference count).

tests/test-keyval.c static void test_keyval_visit_any(void) · line 651

Quoted 1 line
tests/test-keyval.c +0 -0
     qlist = qobject_to_qlist(any);

Reference count unchanged.

tests/test-keyval.c static void test_keyval_visit_any(void) · line 653

Quoted 2 lines
tests/test-keyval.c +1 -0
     g_assert(qlist);
+    qobject_decref(any);

Uh, this is unnecessarily dirty: you relinquish the reference before you're actually done with it. Works only because there's *another* reference hiding within @v. Let's move this ...

tests/test-keyval.c static void test_keyval_visit_any(void) · line 660

Quoted 7 lines
tests/test-keyval.c +2 -0
     qstr = qobject_to_qstring(qlist_pop(qlist));
     g_assert_cmpstr(qstring_get_str(qstr), ==, "null");
+    QDECREF(qstr);
     qstr = qobject_to_qstring(qlist_pop(qlist));
     g_assert_cmpstr(qstring_get_str(qstr), ==, "1");
     g_assert(qlist_empty(qlist));
+    QDECREF(qstr);
Quoted 2 lines

... here. Okay to do that on commit?

sure, makes sense

Quoted 4 lines
Quoted 3 lines
tests/test-keyval.c +0 -0
     visit_check_struct(v, &error_abort);
     visit_end_struct(v, NULL);
     visit_free(v);
Quoted 5 lines
Quoted 4 lines

With the reference counting cleaned up:

thanks

Applied to qapi-next, thanks!