qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] qtest/npcm7xx_pwm-test: Fix memleak in pwm_qom_get
@ 2021-01-15  7:56 Gan Qixin
  2021-01-15  9:15 ` Philippe Mathieu-Daudé
  0 siblings, 1 reply; 4+ messages in thread
From: Gan Qixin @ 2021-01-15  7:56 UTC (permalink / raw)
  To: qemu-devel, qemu-trivial
  Cc: Laurent Vivier, Thomas Huth, zhang.zhanghailiang,
	Havard Skinnemoen, Tyrone Ting, Gan Qixin, Euler Robot,
	kuhn.chenqun

The pwm_qom_get function didn't free "response", which caused an indirect
memory leak. So use qobject_unref() to fix it.

ASAN shows memory leak stack:

Indirect leak of 74160000 byte(s) in 18000 object(s) allocated from:
    #0 0x7f96e2f79d4e in __interceptor_calloc (/lib64/libasan.so.5+0x112d4e)
    #1 0x7f96e2d98a50 in g_malloc0 (/lib64/libglib-2.0.so.0+0x55a50)
    #2 0x556313112180 in qdict_new ../qobject/qdict.c:30
    #3 0x556313115bca in parse_object ../qobject/json-parser.c:318
    #4 0x556313117810 in parse_value ../qobject/json-parser.c:546
    #5 0x556313117bda in json_parser_parse ../qobject/json-parser.c:580
    #6 0x55631310fe67 in json_message_process_token ../qobject/json-streamer.c:92
    #7 0x5563131210b7 in json_lexer_feed_char ../qobject/json-lexer.c:313
    #8 0x556313121662 in json_lexer_feed ../qobject/json-lexer.c:350
    #9 0x5563131101e9 in json_message_parser_feed ../qobject/json-streamer.c:121
    #10 0x5563130cb81e in qmp_fd_receive ../tests/qtest/libqtest.c:614
    #11 0x5563130cba2b in qtest_qmp_receive_dict ../tests/qtest/libqtest.c:636
    #12 0x5563130cb939 in qtest_qmp_receive ../tests/qtest/libqtest.c:624
    #13 0x5563130cbe0d in qtest_vqmp ../tests/qtest/libqtest.c:715
    #14 0x5563130cc40f in qtest_qmp ../tests/qtest/libqtest.c:756
    #15 0x5563130c5623 in pwm_qom_get ../tests/qtest/npcm7xx_pwm-test.c:180
    #16 0x5563130c595e in pwm_get_duty ../tests/qtest/npcm7xx_pwm-test.c:210
    #17 0x5563130c7529 in test_toggle ../tests/qtest/npcm7xx_pwm-test.c:447

Reported-by: Euler Robot <euler.robot@huawei.com>
Signed-off-by: Gan Qixin <ganqixin@huawei.com>
---
Cc: Havard Skinnemoen <hskinnemoen@google.com>
Cc: Tyrone Ting <kfting@nuvoton.com>
Cc: Thomas Huth <thuth@redhat.com>
Cc: Laurent Vivier <lvivier@redhat.com>
---
 tests/qtest/npcm7xx_pwm-test.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/tests/qtest/npcm7xx_pwm-test.c b/tests/qtest/npcm7xx_pwm-test.c
index 33fbdf5f54..63557d2c06 100644
--- a/tests/qtest/npcm7xx_pwm-test.c
+++ b/tests/qtest/npcm7xx_pwm-test.c
@@ -175,6 +175,7 @@ static int pwm_index(const PWM *pwm)
 static uint64_t pwm_qom_get(QTestState *qts, const char *path, const char *name)
 {
     QDict *response;
+    uint64_t val;
 
     g_test_message("Getting properties %s from %s", name, path);
     response = qtest_qmp(qts, "{ 'execute': 'qom-get',"
@@ -182,7 +183,9 @@ static uint64_t pwm_qom_get(QTestState *qts, const char *path, const char *name)
             path, name);
     /* The qom set message returns successfully. */
     g_assert_true(qdict_haskey(response, "return"));
-    return qnum_get_uint(qobject_to(QNum, qdict_get(response, "return")));
+    val = qnum_get_uint(qobject_to(QNum, qdict_get(response, "return")));
+    qobject_unref(response);
+    return val;
 }
 
 static uint64_t pwm_get_freq(QTestState *qts, int module_index, int pwm_index)
-- 
2.27.0



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] qtest/npcm7xx_pwm-test: Fix memleak in pwm_qom_get
  2021-01-15  7:56 [PATCH] qtest/npcm7xx_pwm-test: Fix memleak in pwm_qom_get Gan Qixin
@ 2021-01-15  9:15 ` Philippe Mathieu-Daudé
  2021-01-15 17:17   ` Havard Skinnemoen via
  0 siblings, 1 reply; 4+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-01-15  9:15 UTC (permalink / raw)
  To: Gan Qixin, qemu-devel, qemu-trivial
  Cc: Laurent Vivier, Thomas Huth, zhang.zhanghailiang,
	Havard Skinnemoen, Tyrone Ting, Euler Robot, kuhn.chenqun

On 1/15/21 8:56 AM, Gan Qixin wrote:
> The pwm_qom_get function didn't free "response", which caused an indirect
> memory leak. So use qobject_unref() to fix it.
> 
> ASAN shows memory leak stack:
> 
> Indirect leak of 74160000 byte(s) in 18000 object(s) allocated from:
>     #0 0x7f96e2f79d4e in __interceptor_calloc (/lib64/libasan.so.5+0x112d4e)
>     #1 0x7f96e2d98a50 in g_malloc0 (/lib64/libglib-2.0.so.0+0x55a50)
>     #2 0x556313112180 in qdict_new ../qobject/qdict.c:30
>     #3 0x556313115bca in parse_object ../qobject/json-parser.c:318
>     #4 0x556313117810 in parse_value ../qobject/json-parser.c:546
>     #5 0x556313117bda in json_parser_parse ../qobject/json-parser.c:580
>     #6 0x55631310fe67 in json_message_process_token ../qobject/json-streamer.c:92
>     #7 0x5563131210b7 in json_lexer_feed_char ../qobject/json-lexer.c:313
>     #8 0x556313121662 in json_lexer_feed ../qobject/json-lexer.c:350
>     #9 0x5563131101e9 in json_message_parser_feed ../qobject/json-streamer.c:121
>     #10 0x5563130cb81e in qmp_fd_receive ../tests/qtest/libqtest.c:614
>     #11 0x5563130cba2b in qtest_qmp_receive_dict ../tests/qtest/libqtest.c:636
>     #12 0x5563130cb939 in qtest_qmp_receive ../tests/qtest/libqtest.c:624
>     #13 0x5563130cbe0d in qtest_vqmp ../tests/qtest/libqtest.c:715
>     #14 0x5563130cc40f in qtest_qmp ../tests/qtest/libqtest.c:756
>     #15 0x5563130c5623 in pwm_qom_get ../tests/qtest/npcm7xx_pwm-test.c:180
>     #16 0x5563130c595e in pwm_get_duty ../tests/qtest/npcm7xx_pwm-test.c:210
>     #17 0x5563130c7529 in test_toggle ../tests/qtest/npcm7xx_pwm-test.c:447
> 
> Reported-by: Euler Robot <euler.robot@huawei.com>
> Signed-off-by: Gan Qixin <ganqixin@huawei.com>
> ---
> Cc: Havard Skinnemoen <hskinnemoen@google.com>
> Cc: Tyrone Ting <kfting@nuvoton.com>
> Cc: Thomas Huth <thuth@redhat.com>
> Cc: Laurent Vivier <lvivier@redhat.com>
> ---
>  tests/qtest/npcm7xx_pwm-test.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] qtest/npcm7xx_pwm-test: Fix memleak in pwm_qom_get
  2021-01-15  9:15 ` Philippe Mathieu-Daudé
@ 2021-01-15 17:17   ` Havard Skinnemoen via
  2021-01-15 17:23     ` Hao Wu via
  0 siblings, 1 reply; 4+ messages in thread
From: Havard Skinnemoen via @ 2021-01-15 17:17 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, Hao Wu
  Cc: Laurent Vivier, Thomas Huth, zhang.zhanghailiang, qemu-trivial,
	QEMU Developers, Tyrone Ting, Gan Qixin, Euler Robot, Chen Qun

+Hao Wu

On Fri, Jan 15, 2021 at 1:15 AM Philippe Mathieu-Daudé <f4bug@amsat.org> wrote:
>
> On 1/15/21 8:56 AM, Gan Qixin wrote:
> > The pwm_qom_get function didn't free "response", which caused an indirect
> > memory leak. So use qobject_unref() to fix it.
> >
> > ASAN shows memory leak stack:
> >
> > Indirect leak of 74160000 byte(s) in 18000 object(s) allocated from:
> >     #0 0x7f96e2f79d4e in __interceptor_calloc (/lib64/libasan.so.5+0x112d4e)
> >     #1 0x7f96e2d98a50 in g_malloc0 (/lib64/libglib-2.0.so.0+0x55a50)
> >     #2 0x556313112180 in qdict_new ../qobject/qdict.c:30
> >     #3 0x556313115bca in parse_object ../qobject/json-parser.c:318
> >     #4 0x556313117810 in parse_value ../qobject/json-parser.c:546
> >     #5 0x556313117bda in json_parser_parse ../qobject/json-parser.c:580
> >     #6 0x55631310fe67 in json_message_process_token ../qobject/json-streamer.c:92
> >     #7 0x5563131210b7 in json_lexer_feed_char ../qobject/json-lexer.c:313
> >     #8 0x556313121662 in json_lexer_feed ../qobject/json-lexer.c:350
> >     #9 0x5563131101e9 in json_message_parser_feed ../qobject/json-streamer.c:121
> >     #10 0x5563130cb81e in qmp_fd_receive ../tests/qtest/libqtest.c:614
> >     #11 0x5563130cba2b in qtest_qmp_receive_dict ../tests/qtest/libqtest.c:636
> >     #12 0x5563130cb939 in qtest_qmp_receive ../tests/qtest/libqtest.c:624
> >     #13 0x5563130cbe0d in qtest_vqmp ../tests/qtest/libqtest.c:715
> >     #14 0x5563130cc40f in qtest_qmp ../tests/qtest/libqtest.c:756
> >     #15 0x5563130c5623 in pwm_qom_get ../tests/qtest/npcm7xx_pwm-test.c:180
> >     #16 0x5563130c595e in pwm_get_duty ../tests/qtest/npcm7xx_pwm-test.c:210
> >     #17 0x5563130c7529 in test_toggle ../tests/qtest/npcm7xx_pwm-test.c:447
> >
> > Reported-by: Euler Robot <euler.robot@huawei.com>
> > Signed-off-by: Gan Qixin <ganqixin@huawei.com>
> > ---
> > Cc: Havard Skinnemoen <hskinnemoen@google.com>
> > Cc: Tyrone Ting <kfting@nuvoton.com>
> > Cc: Thomas Huth <thuth@redhat.com>
> > Cc: Laurent Vivier <lvivier@redhat.com>
> > ---
> >  tests/qtest/npcm7xx_pwm-test.c | 5 ++++-
> >  1 file changed, 4 insertions(+), 1 deletion(-)
>
> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

Reviewed-by: Havard Skinnemoen <hskinnemoen@google.com>

Thanks!


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] qtest/npcm7xx_pwm-test: Fix memleak in pwm_qom_get
  2021-01-15 17:17   ` Havard Skinnemoen via
@ 2021-01-15 17:23     ` Hao Wu via
  0 siblings, 0 replies; 4+ messages in thread
From: Hao Wu via @ 2021-01-15 17:23 UTC (permalink / raw)
  To: Havard Skinnemoen
  Cc: Laurent Vivier, Thomas Huth, zhang.zhanghailiang, qemu-trivial,
	Philippe Mathieu-Daudé,
	QEMU Developers, Tyrone Ting, Gan Qixin, Euler Robot, Chen Qun

[-- Attachment #1: Type: text/plain, Size: 2610 bytes --]

On Fri, Jan 15, 2021 at 9:17 AM Havard Skinnemoen <hskinnemoen@google.com>
wrote:

> +Hao Wu
>
> On Fri, Jan 15, 2021 at 1:15 AM Philippe Mathieu-Daudé <f4bug@amsat.org>
> wrote:
> >
> > On 1/15/21 8:56 AM, Gan Qixin wrote:
> > > The pwm_qom_get function didn't free "response", which caused an
> indirect
> > > memory leak. So use qobject_unref() to fix it.
> > >
> > > ASAN shows memory leak stack:
> > >
> > > Indirect leak of 74160000 byte(s) in 18000 object(s) allocated from:
> > >     #0 0x7f96e2f79d4e in __interceptor_calloc
> (/lib64/libasan.so.5+0x112d4e)
> > >     #1 0x7f96e2d98a50 in g_malloc0 (/lib64/libglib-2.0.so.0+0x55a50)
> > >     #2 0x556313112180 in qdict_new ../qobject/qdict.c:30
> > >     #3 0x556313115bca in parse_object ../qobject/json-parser.c:318
> > >     #4 0x556313117810 in parse_value ../qobject/json-parser.c:546
> > >     #5 0x556313117bda in json_parser_parse ../qobject/json-parser.c:580
> > >     #6 0x55631310fe67 in json_message_process_token
> ../qobject/json-streamer.c:92
> > >     #7 0x5563131210b7 in json_lexer_feed_char
> ../qobject/json-lexer.c:313
> > >     #8 0x556313121662 in json_lexer_feed ../qobject/json-lexer.c:350
> > >     #9 0x5563131101e9 in json_message_parser_feed
> ../qobject/json-streamer.c:121
> > >     #10 0x5563130cb81e in qmp_fd_receive ../tests/qtest/libqtest.c:614
> > >     #11 0x5563130cba2b in qtest_qmp_receive_dict
> ../tests/qtest/libqtest.c:636
> > >     #12 0x5563130cb939 in qtest_qmp_receive
> ../tests/qtest/libqtest.c:624
> > >     #13 0x5563130cbe0d in qtest_vqmp ../tests/qtest/libqtest.c:715
> > >     #14 0x5563130cc40f in qtest_qmp ../tests/qtest/libqtest.c:756
> > >     #15 0x5563130c5623 in pwm_qom_get
> ../tests/qtest/npcm7xx_pwm-test.c:180
> > >     #16 0x5563130c595e in pwm_get_duty
> ../tests/qtest/npcm7xx_pwm-test.c:210
> > >     #17 0x5563130c7529 in test_toggle
> ../tests/qtest/npcm7xx_pwm-test.c:447
> > >
> > > Reported-by: Euler Robot <euler.robot@huawei.com>
> > > Signed-off-by: Gan Qixin <ganqixin@huawei.com>
> > > ---
> > > Cc: Havard Skinnemoen <hskinnemoen@google.com>
> > > Cc: Tyrone Ting <kfting@nuvoton.com>
> > > Cc: Thomas Huth <thuth@redhat.com>
> > > Cc: Laurent Vivier <lvivier@redhat.com>
> > > ---
> > >  tests/qtest/npcm7xx_pwm-test.c | 5 ++++-
> > >  1 file changed, 4 insertions(+), 1 deletion(-)
> >
> > Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
>
> Reviewed-by: Havard Skinnemoen <hskinnemoen@google.com>
>
Reviewed-by: Hao Wu <wuhaotsh@google.com>

Thank you for finding this out!

>
> Thanks!
>

[-- Attachment #2: Type: text/html, Size: 4039 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-01-15 17:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-15  7:56 [PATCH] qtest/npcm7xx_pwm-test: Fix memleak in pwm_qom_get Gan Qixin
2021-01-15  9:15 ` Philippe Mathieu-Daudé
2021-01-15 17:17   ` Havard Skinnemoen via
2021-01-15 17:23     ` Hao Wu via

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).