diff mbox

test-keyval: fix leaks

Message ID 20170410142112.11550-1-marcandre.lureau@redhat.com
State New
Headers show

Commit Message

Marc-André Lureau April 10, 2017, 2:21 p.m. UTC
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 tests/test-keyval.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Eric Blake April 10, 2017, 3:28 p.m. UTC | #1
On 04/10/2017 09:21 AM, Marc-André Lureau wrote:
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  tests/test-keyval.c | 4 ++++
>  1 file changed, 4 insertions(+)

Reviewed-by: Eric Blake <eblake@redhat.com>

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.
Markus Armbruster April 12, 2017, 11:19 a.m. UTC | #2
Marc-André Lureau <marcandre.lureau@redhat.com> writes:

> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  tests/test-keyval.c | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/tests/test-keyval.c b/tests/test-keyval.c
> index ba19560a22..141ee5d0c4 100644
> --- a/tests/test-keyval.c
> +++ b/tests/test-keyval.c
> @@ -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);

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

>      qlist = qobject_to_qlist(any);

Reference count unchanged.

>      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 ...

>      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?

>      visit_check_struct(v, &error_abort);
>      visit_end_struct(v, NULL);
>      visit_free(v);

With the reference counting cleaned up:
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Marc-André Lureau April 12, 2017, 2:33 p.m. UTC | #3
Hi

On Wed, Apr 12, 2017 at 3:19 PM Markus Armbruster <armbru@redhat.com> wrote:

> Marc-André Lureau <marcandre.lureau@redhat.com> writes:
>
> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > ---
> >  tests/test-keyval.c | 4 ++++
> >  1 file changed, 4 insertions(+)
> >
> > diff --git a/tests/test-keyval.c b/tests/test-keyval.c
> > index ba19560a22..141ee5d0c4 100644
> > --- a/tests/test-keyval.c
> > +++ b/tests/test-keyval.c
> > @@ -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);
>
> @any becomes a strong reference (qobject_input_type_any() increments the
> reference count).
>
> >      qlist = qobject_to_qlist(any);
>
> Reference count unchanged.
>
> >      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 ...
>
> >      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?
>

 sure, makes sense


> >      visit_check_struct(v, &error_abort);
> >      visit_end_struct(v, NULL);
> >      visit_free(v);
>
> With the reference counting cleaned up:
> Reviewed-by: Markus Armbruster <armbru@redhat.com>
>
>
thanks
Markus Armbruster April 12, 2017, 2:56 p.m. UTC | #4
Marc-André Lureau <marcandre.lureau@gmail.com> writes:

> Hi
>
> On Wed, Apr 12, 2017 at 3:19 PM Markus Armbruster <armbru@redhat.com> wrote:
>
>> Marc-André Lureau <marcandre.lureau@redhat.com> writes:
>>
>> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
>> > ---
>> >  tests/test-keyval.c | 4 ++++
>> >  1 file changed, 4 insertions(+)
>> >
>> > diff --git a/tests/test-keyval.c b/tests/test-keyval.c
>> > index ba19560a22..141ee5d0c4 100644
>> > --- a/tests/test-keyval.c
>> > +++ b/tests/test-keyval.c
>> > @@ -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);
>>
>> @any becomes a strong reference (qobject_input_type_any() increments the
>> reference count).
>>
>> >      qlist = qobject_to_qlist(any);
>>
>> Reference count unchanged.
>>
>> >      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 ...
>>
>> >      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?
>>
>
>  sure, makes sense
>
>
>> >      visit_check_struct(v, &error_abort);
>> >      visit_end_struct(v, NULL);
>> >      visit_free(v);
>>
>> With the reference counting cleaned up:
>> Reviewed-by: Markus Armbruster <armbru@redhat.com>
>>
>>
> thanks

Applied to qapi-next, thanks!
diff mbox

Patch

diff --git a/tests/test-keyval.c b/tests/test-keyval.c
index ba19560a22..141ee5d0c4 100644
--- a/tests/test-keyval.c
+++ b/tests/test-keyval.c
@@ -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);