* [PATCH] hmp: fix memory leak in qom_composition_compare()
@ 2020-07-14 15:11 Li Qiang
2020-07-14 16:47 ` Philippe Mathieu-Daudé
0 siblings, 1 reply; 3+ messages in thread
From: Li Qiang @ 2020-07-14 15:11 UTC (permalink / raw)
To: pbonzini, berrange, ehabkost, armbru; +Cc: Li Qiang, liq3ea, qemu-devel
While 'make chekc', I got following error:
root@ubuntu:~/qemu# ./tests/qtest/device-introspect-test
/x86_64/device/introspect/list: OK
/x86_64/device/introspect/list-fields: OK
/x86_64/device/introspect/none:
=================================================================
==53741==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 212 byte(s) in 20 object(s) allocated from:
#0 0x7f3b6319cb40 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdeb40)
#1 0x7f3b62805ab8 in g_malloc (/usr/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x51ab8)
SUMMARY: AddressSanitizer: 212 byte(s) leaked in 20 allocation(s).
tests/qtest/libqtest.c:166: kill_qemu() tried to terminate QEMU process but encountered exit status 1 (expected 0)
Aborted (core dumped)
This is because the 'info qom-tree' path has a memory leak and qemu
exit 1. The leak is in 'qom_composition_compare'. This patch fixes this.
Fixes: e8c9e65816f("qom: Make "info qom-tree" show children sorted")
Signed-off-by: Li Qiang <liq3ea@163.com>
---
qom/qom-hmp-cmds.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/qom/qom-hmp-cmds.c b/qom/qom-hmp-cmds.c
index 9ed8bb1c9f..3547d5ba4e 100644
--- a/qom/qom-hmp-cmds.c
+++ b/qom/qom-hmp-cmds.c
@@ -96,8 +96,10 @@ static void print_qom_composition(Monitor *mon, Object *obj, int indent);
static int qom_composition_compare(const void *a, const void *b, void *ignore)
{
- return g_strcmp0(a ? object_get_canonical_path_component(a) : NULL,
- b ? object_get_canonical_path_component(b) : NULL);
+ g_autofree char *t1 = a ? object_get_canonical_path_component(a) : NULL;
+ g_autofree char *t2 = b ? object_get_canonical_path_component(b) : NULL;
+
+ return g_strcmp0(t1, t2);
}
static int insert_qom_composition_child(Object *obj, void *opaque)
--
2.17.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] hmp: fix memory leak in qom_composition_compare()
2020-07-14 15:11 [PATCH] hmp: fix memory leak in qom_composition_compare() Li Qiang
@ 2020-07-14 16:47 ` Philippe Mathieu-Daudé
2020-07-14 17:20 ` Li Qiang
0 siblings, 1 reply; 3+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-07-14 16:47 UTC (permalink / raw)
To: Li Qiang, pbonzini, berrange, ehabkost, armbru; +Cc: liq3ea, qemu-devel
On 7/14/20 5:11 PM, Li Qiang wrote:
> While 'make chekc', I got following error:
>
> root@ubuntu:~/qemu# ./tests/qtest/device-introspect-test
> /x86_64/device/introspect/list: OK
> /x86_64/device/introspect/list-fields: OK
> /x86_64/device/introspect/none:
> =================================================================
> ==53741==ERROR: LeakSanitizer: detected memory leaks
>
> Direct leak of 212 byte(s) in 20 object(s) allocated from:
> #0 0x7f3b6319cb40 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdeb40)
> #1 0x7f3b62805ab8 in g_malloc (/usr/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x51ab8)
>
> SUMMARY: AddressSanitizer: 212 byte(s) leaked in 20 allocation(s).
> tests/qtest/libqtest.c:166: kill_qemu() tried to terminate QEMU process but encountered exit status 1 (expected 0)
> Aborted (core dumped)
>
> This is because the 'info qom-tree' path has a memory leak and qemu
> exit 1. The leak is in 'qom_composition_compare'. This patch fixes this.
>
> Fixes: e8c9e65816f("qom: Make "info qom-tree" show children sorted")
> Signed-off-by: Li Qiang <liq3ea@163.com>
> ---
> qom/qom-hmp-cmds.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/qom/qom-hmp-cmds.c b/qom/qom-hmp-cmds.c
> index 9ed8bb1c9f..3547d5ba4e 100644
> --- a/qom/qom-hmp-cmds.c
> +++ b/qom/qom-hmp-cmds.c
> @@ -96,8 +96,10 @@ static void print_qom_composition(Monitor *mon, Object *obj, int indent);
>
> static int qom_composition_compare(const void *a, const void *b, void *ignore)
> {
> - return g_strcmp0(a ? object_get_canonical_path_component(a) : NULL,
> - b ? object_get_canonical_path_component(b) : NULL);
> + g_autofree char *t1 = a ? object_get_canonical_path_component(a) : NULL;
> + g_autofree char *t2 = b ? object_get_canonical_path_component(b) : NULL;
> +
> + return g_strcmp0(t1, t2);
> }
>
> static int insert_qom_composition_child(Object *obj, void *opaque)
>
Ah you won the race with Markus:
https://lists.gnu.org/archive/html/qemu-devel/2020-07/msg04740.html
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] hmp: fix memory leak in qom_composition_compare()
2020-07-14 16:47 ` Philippe Mathieu-Daudé
@ 2020-07-14 17:20 ` Li Qiang
0 siblings, 0 replies; 3+ messages in thread
From: Li Qiang @ 2020-07-14 17:20 UTC (permalink / raw)
To: Philippe Mathieu-Daudé
Cc: Daniel P. Berrange, Eduardo Habkost, Li Qiang, Qemu Developers,
Markus Armbruster, Paolo Bonzini
Philippe Mathieu-Daudé <philmd@redhat.com> 于2020年7月15日周三 上午12:47写道:
>
> On 7/14/20 5:11 PM, Li Qiang wrote:
> > While 'make chekc', I got following error:
> >
> > root@ubuntu:~/qemu# ./tests/qtest/device-introspect-test
> > /x86_64/device/introspect/list: OK
> > /x86_64/device/introspect/list-fields: OK
> > /x86_64/device/introspect/none:
> > =================================================================
> > ==53741==ERROR: LeakSanitizer: detected memory leaks
> >
> > Direct leak of 212 byte(s) in 20 object(s) allocated from:
> > #0 0x7f3b6319cb40 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdeb40)
> > #1 0x7f3b62805ab8 in g_malloc (/usr/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x51ab8)
> >
> > SUMMARY: AddressSanitizer: 212 byte(s) leaked in 20 allocation(s).
> > tests/qtest/libqtest.c:166: kill_qemu() tried to terminate QEMU process but encountered exit status 1 (expected 0)
> > Aborted (core dumped)
> >
> > This is because the 'info qom-tree' path has a memory leak and qemu
> > exit 1. The leak is in 'qom_composition_compare'. This patch fixes this.
> >
> > Fixes: e8c9e65816f("qom: Make "info qom-tree" show children sorted")
> > Signed-off-by: Li Qiang <liq3ea@163.com>
> > ---
> > qom/qom-hmp-cmds.c | 6 ++++--
> > 1 file changed, 4 insertions(+), 2 deletions(-)
> >
> > diff --git a/qom/qom-hmp-cmds.c b/qom/qom-hmp-cmds.c
> > index 9ed8bb1c9f..3547d5ba4e 100644
> > --- a/qom/qom-hmp-cmds.c
> > +++ b/qom/qom-hmp-cmds.c
> > @@ -96,8 +96,10 @@ static void print_qom_composition(Monitor *mon, Object *obj, int indent);
> >
> > static int qom_composition_compare(const void *a, const void *b, void *ignore)
> > {
> > - return g_strcmp0(a ? object_get_canonical_path_component(a) : NULL,
> > - b ? object_get_canonical_path_component(b) : NULL);
> > + g_autofree char *t1 = a ? object_get_canonical_path_component(a) : NULL;
> > + g_autofree char *t2 = b ? object_get_canonical_path_component(b) : NULL;
> > +
> > + return g_strcmp0(t1, t2);
> > }
> >
> > static int insert_qom_composition_child(Object *obj, void *opaque)
> >
>
> Ah you won the race with Markus:
> https://lists.gnu.org/archive/html/qemu-devel/2020-07/msg04740.html
>
Oh interesting, I just want to begin to write the e1000e tx bh
discussed with Jason.
But found there are some memleak issue.
> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-07-14 17:21 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-14 15:11 [PATCH] hmp: fix memory leak in qom_composition_compare() Li Qiang
2020-07-14 16:47 ` Philippe Mathieu-Daudé
2020-07-14 17:20 ` Li Qiang
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.