[Qemu-devel] [PATCH] tests/check-qjson: fix a leak

Marc-André Lureau posted 1 patch 7 years, 2 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20180901211917.10372-1-marcandre.lureau@redhat.com
Test docker-clang@ubuntu failed
Test checkpatch passed
tests/check-qjson.c | 1 +
1 file changed, 1 insertion(+)
[Qemu-devel] [PATCH] tests/check-qjson: fix a leak
Posted by Marc-André Lureau 7 years, 2 months ago
Spotted by ASAN:
=================================================================
==11893==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 1120 byte(s) in 28 object(s) allocated from:
    #0 0x7fd0515b0c48 in malloc (/lib64/libasan.so.5+0xeec48)
    #1 0x7fd050ffa3c5 in g_malloc (/lib64/libglib-2.0.so.0+0x523c5)
    #2 0x559e708b56a4 in qstring_from_str /home/elmarco/src/qq/qobject/qstring.c:66
    #3 0x559e708b4fe0 in qstring_new /home/elmarco/src/qq/qobject/qstring.c:23
    #4 0x559e708bda7d in parse_string /home/elmarco/src/qq/qobject/json-parser.c:143
    #5 0x559e708c1009 in parse_literal /home/elmarco/src/qq/qobject/json-parser.c:484
    #6 0x559e708c1627 in parse_value /home/elmarco/src/qq/qobject/json-parser.c:547
    #7 0x559e708c1c67 in json_parser_parse /home/elmarco/src/qq/qobject/json-parser.c:573
    #8 0x559e708bc0ff in json_message_process_token /home/elmarco/src/qq/qobject/json-streamer.c:92
    #9 0x559e708d1655 in json_lexer_feed_char /home/elmarco/src/qq/qobject/json-lexer.c:292
    #10 0x559e708d1fe1 in json_lexer_feed /home/elmarco/src/qq/qobject/json-lexer.c:339
    #11 0x559e708bc856 in json_message_parser_feed /home/elmarco/src/qq/qobject/json-streamer.c:121
    #12 0x559e708b8b4b in qobject_from_jsonv /home/elmarco/src/qq/qobject/qjson.c:69
    #13 0x559e708b8d02 in qobject_from_json /home/elmarco/src/qq/qobject/qjson.c:83
    #14 0x559e708a74ae in from_json_str /home/elmarco/src/qq/tests/check-qjson.c:30
    #15 0x559e708a9f83 in utf8_string /home/elmarco/src/qq/tests/check-qjson.c:781
    #16 0x7fd05101bc49 in test_case_run gtestutils.c:2255
    #17 0x7fd05101bc49 in g_test_run_suite_internal gtestutils.c:2339

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 tests/check-qjson.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tests/check-qjson.c b/tests/check-qjson.c
index cc13f3d41e..d876a7a96e 100644
--- a/tests/check-qjson.c
+++ b/tests/check-qjson.c
@@ -780,6 +780,7 @@ static void utf8_string(void)
             if (!strstr(json_out, "\\uFFFD")) {
                 str = from_json_str(json_out, j, &error_abort);
                 g_assert_cmpstr(qstring_get_try_str(str), ==, utf8_in);
+                qobject_unref(str);
             }
         }
     }
-- 
2.19.0.rc1


Re: [Qemu-devel] [PATCH] tests/check-qjson: fix a leak
Posted by Thomas Huth 7 years, 2 months ago
On 2018-09-01 23:19, Marc-André Lureau wrote:
> Spotted by ASAN:
> =================================================================
> ==11893==ERROR: LeakSanitizer: detected memory leaks
> 
> Direct leak of 1120 byte(s) in 28 object(s) allocated from:
>     #0 0x7fd0515b0c48 in malloc (/lib64/libasan.so.5+0xeec48)
>     #1 0x7fd050ffa3c5 in g_malloc (/lib64/libglib-2.0.so.0+0x523c5)
>     #2 0x559e708b56a4 in qstring_from_str /home/elmarco/src/qq/qobject/qstring.c:66
>     #3 0x559e708b4fe0 in qstring_new /home/elmarco/src/qq/qobject/qstring.c:23
>     #4 0x559e708bda7d in parse_string /home/elmarco/src/qq/qobject/json-parser.c:143
>     #5 0x559e708c1009 in parse_literal /home/elmarco/src/qq/qobject/json-parser.c:484
>     #6 0x559e708c1627 in parse_value /home/elmarco/src/qq/qobject/json-parser.c:547
>     #7 0x559e708c1c67 in json_parser_parse /home/elmarco/src/qq/qobject/json-parser.c:573
>     #8 0x559e708bc0ff in json_message_process_token /home/elmarco/src/qq/qobject/json-streamer.c:92
>     #9 0x559e708d1655 in json_lexer_feed_char /home/elmarco/src/qq/qobject/json-lexer.c:292
>     #10 0x559e708d1fe1 in json_lexer_feed /home/elmarco/src/qq/qobject/json-lexer.c:339
>     #11 0x559e708bc856 in json_message_parser_feed /home/elmarco/src/qq/qobject/json-streamer.c:121
>     #12 0x559e708b8b4b in qobject_from_jsonv /home/elmarco/src/qq/qobject/qjson.c:69
>     #13 0x559e708b8d02 in qobject_from_json /home/elmarco/src/qq/qobject/qjson.c:83
>     #14 0x559e708a74ae in from_json_str /home/elmarco/src/qq/tests/check-qjson.c:30
>     #15 0x559e708a9f83 in utf8_string /home/elmarco/src/qq/tests/check-qjson.c:781
>     #16 0x7fd05101bc49 in test_case_run gtestutils.c:2255
>     #17 0x7fd05101bc49 in g_test_run_suite_internal gtestutils.c:2339
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  tests/check-qjson.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/tests/check-qjson.c b/tests/check-qjson.c
> index cc13f3d41e..d876a7a96e 100644
> --- a/tests/check-qjson.c
> +++ b/tests/check-qjson.c
> @@ -780,6 +780,7 @@ static void utf8_string(void)
>              if (!strstr(json_out, "\\uFFFD")) {
>                  str = from_json_str(json_out, j, &error_abort);
>                  g_assert_cmpstr(qstring_get_try_str(str), ==, utf8_in);
> +                qobject_unref(str);
>              }
>          }
>      }
> 

There are other occurances of from_json_str() which are not followed by
an object_unref() ... do they need to be fixed as well?
(e.g. at the end of escaped_string(), or earlier in utf8_string())

 Thomas

Re: [Qemu-devel] [PATCH] tests/check-qjson: fix a leak
Posted by Markus Armbruster 7 years, 2 months ago
Thomas Huth <thuth@redhat.com> writes:

> On 2018-09-01 23:19, Marc-André Lureau wrote:
>> Spotted by ASAN:
>> =================================================================
>> ==11893==ERROR: LeakSanitizer: detected memory leaks
>> 
>> Direct leak of 1120 byte(s) in 28 object(s) allocated from:
>>     #0 0x7fd0515b0c48 in malloc (/lib64/libasan.so.5+0xeec48)
>>     #1 0x7fd050ffa3c5 in g_malloc (/lib64/libglib-2.0.so.0+0x523c5)
>>     #2 0x559e708b56a4 in qstring_from_str /home/elmarco/src/qq/qobject/qstring.c:66
>>     #3 0x559e708b4fe0 in qstring_new /home/elmarco/src/qq/qobject/qstring.c:23
>>     #4 0x559e708bda7d in parse_string /home/elmarco/src/qq/qobject/json-parser.c:143
>>     #5 0x559e708c1009 in parse_literal /home/elmarco/src/qq/qobject/json-parser.c:484
>>     #6 0x559e708c1627 in parse_value /home/elmarco/src/qq/qobject/json-parser.c:547
>>     #7 0x559e708c1c67 in json_parser_parse /home/elmarco/src/qq/qobject/json-parser.c:573
>>     #8 0x559e708bc0ff in json_message_process_token /home/elmarco/src/qq/qobject/json-streamer.c:92
>>     #9 0x559e708d1655 in json_lexer_feed_char /home/elmarco/src/qq/qobject/json-lexer.c:292
>>     #10 0x559e708d1fe1 in json_lexer_feed /home/elmarco/src/qq/qobject/json-lexer.c:339
>>     #11 0x559e708bc856 in json_message_parser_feed /home/elmarco/src/qq/qobject/json-streamer.c:121
>>     #12 0x559e708b8b4b in qobject_from_jsonv /home/elmarco/src/qq/qobject/qjson.c:69
>>     #13 0x559e708b8d02 in qobject_from_json /home/elmarco/src/qq/qobject/qjson.c:83
>>     #14 0x559e708a74ae in from_json_str /home/elmarco/src/qq/tests/check-qjson.c:30
>>     #15 0x559e708a9f83 in utf8_string /home/elmarco/src/qq/tests/check-qjson.c:781
>>     #16 0x7fd05101bc49 in test_case_run gtestutils.c:2255
>>     #17 0x7fd05101bc49 in g_test_run_suite_internal gtestutils.c:2339
>> 
>> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
>> ---
>>  tests/check-qjson.c | 1 +
>>  1 file changed, 1 insertion(+)
>> 
>> diff --git a/tests/check-qjson.c b/tests/check-qjson.c
>> index cc13f3d41e..d876a7a96e 100644
>> --- a/tests/check-qjson.c
>> +++ b/tests/check-qjson.c
>> @@ -780,6 +780,7 @@ static void utf8_string(void)
>>              if (!strstr(json_out, "\\uFFFD")) {
>>                  str = from_json_str(json_out, j, &error_abort);
>>                  g_assert_cmpstr(qstring_get_try_str(str), ==, utf8_in);
>> +                qobject_unref(str);
>>              }
>>          }
>>      }
>> 
>
> There are other occurances of from_json_str() which are not followed by
> an object_unref() ... do they need to be fixed as well?
> (e.g. at the end of escaped_string(), or earlier in utf8_string())

These are all asserted to be null, aren't they?

Re: [Qemu-devel] [PATCH] tests/check-qjson: fix a leak
Posted by Thomas Huth 7 years, 2 months ago
On 2018-09-03 07:51, Markus Armbruster wrote:
> Thomas Huth <thuth@redhat.com> writes:
> 
>> On 2018-09-01 23:19, Marc-André Lureau wrote:
>>> Spotted by ASAN:
>>> =================================================================
>>> ==11893==ERROR: LeakSanitizer: detected memory leaks
>>>
>>> Direct leak of 1120 byte(s) in 28 object(s) allocated from:
>>>     #0 0x7fd0515b0c48 in malloc (/lib64/libasan.so.5+0xeec48)
>>>     #1 0x7fd050ffa3c5 in g_malloc (/lib64/libglib-2.0.so.0+0x523c5)
>>>     #2 0x559e708b56a4 in qstring_from_str /home/elmarco/src/qq/qobject/qstring.c:66
>>>     #3 0x559e708b4fe0 in qstring_new /home/elmarco/src/qq/qobject/qstring.c:23
>>>     #4 0x559e708bda7d in parse_string /home/elmarco/src/qq/qobject/json-parser.c:143
>>>     #5 0x559e708c1009 in parse_literal /home/elmarco/src/qq/qobject/json-parser.c:484
>>>     #6 0x559e708c1627 in parse_value /home/elmarco/src/qq/qobject/json-parser.c:547
>>>     #7 0x559e708c1c67 in json_parser_parse /home/elmarco/src/qq/qobject/json-parser.c:573
>>>     #8 0x559e708bc0ff in json_message_process_token /home/elmarco/src/qq/qobject/json-streamer.c:92
>>>     #9 0x559e708d1655 in json_lexer_feed_char /home/elmarco/src/qq/qobject/json-lexer.c:292
>>>     #10 0x559e708d1fe1 in json_lexer_feed /home/elmarco/src/qq/qobject/json-lexer.c:339
>>>     #11 0x559e708bc856 in json_message_parser_feed /home/elmarco/src/qq/qobject/json-streamer.c:121
>>>     #12 0x559e708b8b4b in qobject_from_jsonv /home/elmarco/src/qq/qobject/qjson.c:69
>>>     #13 0x559e708b8d02 in qobject_from_json /home/elmarco/src/qq/qobject/qjson.c:83
>>>     #14 0x559e708a74ae in from_json_str /home/elmarco/src/qq/tests/check-qjson.c:30
>>>     #15 0x559e708a9f83 in utf8_string /home/elmarco/src/qq/tests/check-qjson.c:781
>>>     #16 0x7fd05101bc49 in test_case_run gtestutils.c:2255
>>>     #17 0x7fd05101bc49 in g_test_run_suite_internal gtestutils.c:2339
>>>
>>> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
>>> ---
>>>  tests/check-qjson.c | 1 +
>>>  1 file changed, 1 insertion(+)
>>>
>>> diff --git a/tests/check-qjson.c b/tests/check-qjson.c
>>> index cc13f3d41e..d876a7a96e 100644
>>> --- a/tests/check-qjson.c
>>> +++ b/tests/check-qjson.c
>>> @@ -780,6 +780,7 @@ static void utf8_string(void)
>>>              if (!strstr(json_out, "\\uFFFD")) {
>>>                  str = from_json_str(json_out, j, &error_abort);
>>>                  g_assert_cmpstr(qstring_get_try_str(str), ==, utf8_in);
>>> +                qobject_unref(str);
>>>              }
>>>          }
>>>      }
>>>
>>
>> There are other occurances of from_json_str() which are not followed by
>> an object_unref() ... do they need to be fixed as well?
>> (e.g. at the end of escaped_string(), or earlier in utf8_string())
> 
> These are all asserted to be null, aren't they?

Ah, right, sorry, it's still too early in the morning here, I guess ;-)

 Thomas

Re: [Qemu-devel] [PATCH] tests/check-qjson: fix a leak
Posted by Markus Armbruster 7 years, 2 months ago
Thomas Huth <thuth@redhat.com> writes:

> On 2018-09-03 07:51, Markus Armbruster wrote:
>> Thomas Huth <thuth@redhat.com> writes:
>> 
>>> On 2018-09-01 23:19, Marc-André Lureau wrote:
>>>> Spotted by ASAN:
>>>> =================================================================
>>>> ==11893==ERROR: LeakSanitizer: detected memory leaks
>>>>
>>>> Direct leak of 1120 byte(s) in 28 object(s) allocated from:
>>>>     #0 0x7fd0515b0c48 in malloc (/lib64/libasan.so.5+0xeec48)
>>>>     #1 0x7fd050ffa3c5 in g_malloc (/lib64/libglib-2.0.so.0+0x523c5)
>>>>     #2 0x559e708b56a4 in qstring_from_str /home/elmarco/src/qq/qobject/qstring.c:66
>>>>     #3 0x559e708b4fe0 in qstring_new /home/elmarco/src/qq/qobject/qstring.c:23
>>>>     #4 0x559e708bda7d in parse_string /home/elmarco/src/qq/qobject/json-parser.c:143
>>>>     #5 0x559e708c1009 in parse_literal /home/elmarco/src/qq/qobject/json-parser.c:484
>>>>     #6 0x559e708c1627 in parse_value /home/elmarco/src/qq/qobject/json-parser.c:547
>>>>     #7 0x559e708c1c67 in json_parser_parse /home/elmarco/src/qq/qobject/json-parser.c:573
>>>>     #8 0x559e708bc0ff in json_message_process_token /home/elmarco/src/qq/qobject/json-streamer.c:92
>>>>     #9 0x559e708d1655 in json_lexer_feed_char /home/elmarco/src/qq/qobject/json-lexer.c:292
>>>>     #10 0x559e708d1fe1 in json_lexer_feed /home/elmarco/src/qq/qobject/json-lexer.c:339
>>>>     #11 0x559e708bc856 in json_message_parser_feed /home/elmarco/src/qq/qobject/json-streamer.c:121
>>>>     #12 0x559e708b8b4b in qobject_from_jsonv /home/elmarco/src/qq/qobject/qjson.c:69
>>>>     #13 0x559e708b8d02 in qobject_from_json /home/elmarco/src/qq/qobject/qjson.c:83
>>>>     #14 0x559e708a74ae in from_json_str /home/elmarco/src/qq/tests/check-qjson.c:30
>>>>     #15 0x559e708a9f83 in utf8_string /home/elmarco/src/qq/tests/check-qjson.c:781
>>>>     #16 0x7fd05101bc49 in test_case_run gtestutils.c:2255
>>>>     #17 0x7fd05101bc49 in g_test_run_suite_internal gtestutils.c:2339
>>>>
>>>> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
>>>> ---
>>>>  tests/check-qjson.c | 1 +
>>>>  1 file changed, 1 insertion(+)
>>>>
>>>> diff --git a/tests/check-qjson.c b/tests/check-qjson.c
>>>> index cc13f3d41e..d876a7a96e 100644
>>>> --- a/tests/check-qjson.c
>>>> +++ b/tests/check-qjson.c
>>>> @@ -780,6 +780,7 @@ static void utf8_string(void)
>>>>              if (!strstr(json_out, "\\uFFFD")) {
>>>>                  str = from_json_str(json_out, j, &error_abort);
>>>>                  g_assert_cmpstr(qstring_get_try_str(str), ==, utf8_in);
>>>> +                qobject_unref(str);
>>>>              }
>>>>          }
>>>>      }
>>>>
>>>
>>> There are other occurances of from_json_str() which are not followed by
>>> an object_unref() ... do they need to be fixed as well?
>>> (e.g. at the end of escaped_string(), or earlier in utf8_string())
>> 
>> These are all asserted to be null, aren't they?
>
> Ah, right, sorry, it's still too early in the morning here, I guess ;-)

I was about to write "I should've waited for the coffee to kick in" when
I remembered what g_assert(!str) means :)

Re: [Qemu-devel] [PATCH] tests/check-qjson: fix a leak
Posted by Markus Armbruster 7 years, 2 months ago
Marc-André Lureau <marcandre.lureau@redhat.com> writes:

> Spotted by ASAN:
> =================================================================
> ==11893==ERROR: LeakSanitizer: detected memory leaks
>
> Direct leak of 1120 byte(s) in 28 object(s) allocated from:
>     #0 0x7fd0515b0c48 in malloc (/lib64/libasan.so.5+0xeec48)
>     #1 0x7fd050ffa3c5 in g_malloc (/lib64/libglib-2.0.so.0+0x523c5)
>     #2 0x559e708b56a4 in qstring_from_str /home/elmarco/src/qq/qobject/qstring.c:66
>     #3 0x559e708b4fe0 in qstring_new /home/elmarco/src/qq/qobject/qstring.c:23
>     #4 0x559e708bda7d in parse_string /home/elmarco/src/qq/qobject/json-parser.c:143
>     #5 0x559e708c1009 in parse_literal /home/elmarco/src/qq/qobject/json-parser.c:484
>     #6 0x559e708c1627 in parse_value /home/elmarco/src/qq/qobject/json-parser.c:547
>     #7 0x559e708c1c67 in json_parser_parse /home/elmarco/src/qq/qobject/json-parser.c:573
>     #8 0x559e708bc0ff in json_message_process_token /home/elmarco/src/qq/qobject/json-streamer.c:92
>     #9 0x559e708d1655 in json_lexer_feed_char /home/elmarco/src/qq/qobject/json-lexer.c:292
>     #10 0x559e708d1fe1 in json_lexer_feed /home/elmarco/src/qq/qobject/json-lexer.c:339
>     #11 0x559e708bc856 in json_message_parser_feed /home/elmarco/src/qq/qobject/json-streamer.c:121
>     #12 0x559e708b8b4b in qobject_from_jsonv /home/elmarco/src/qq/qobject/qjson.c:69
>     #13 0x559e708b8d02 in qobject_from_json /home/elmarco/src/qq/qobject/qjson.c:83
>     #14 0x559e708a74ae in from_json_str /home/elmarco/src/qq/tests/check-qjson.c:30
>     #15 0x559e708a9f83 in utf8_string /home/elmarco/src/qq/tests/check-qjson.c:781
>     #16 0x7fd05101bc49 in test_case_run gtestutils.c:2255
>     #17 0x7fd05101bc49 in g_test_run_suite_internal gtestutils.c:2339
>
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  tests/check-qjson.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/tests/check-qjson.c b/tests/check-qjson.c
> index cc13f3d41e..d876a7a96e 100644
> --- a/tests/check-qjson.c
> +++ b/tests/check-qjson.c
> @@ -780,6 +780,7 @@ static void utf8_string(void)
>              if (!strstr(json_out, "\\uFFFD")) {
>                  str = from_json_str(json_out, j, &error_abort);
>                  g_assert_cmpstr(qstring_get_try_str(str), ==, utf8_in);
> +                qobject_unref(str);
>              }
>          }
>      }

Reviewed-by: Markus Armbruster <armbru@redhat.com>

Queued, thanks!