hmp: fix memory leak in qom_composition_compare()
PATCH 1/1 hmp: fix memory leak in qom_composition_compare()
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.
--- qom/qom-hmp-cmds.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
qom/qom-hmp-cmds.c +4 -2
@@ -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)
Signature · 1 line
2.17.1
Quoted 34 lines · Li Qiang
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 leaksDirect 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 <[email protected]>--- qom/qom-hmp-cmds.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)qom/qom-hmp-cmds.c +0
-0@@ -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)
qom/qom-hmp-cmds.c static void print_qom_composition(Monitor *mon, Object *obj, int indent); · line 105
Quoted 10 lines
qom/qom-hmp-cmds.c +4
-2{ -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
Quoted 44 lines · Philippe Mathieu-Daudé <[email protected]> 于2020年7月15日周三 上午12:47写道:
Quoted 42 lines · Li Qiang
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 leaksDirect 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 <[email protected]>--- qom/qom-hmp-cmds.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)qom/qom-hmp-cmds.c +4
-2@@ -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); }
Quoted 6 lines
qom/qom-hmp-cmds.c static void print_qom_composition(Monitor *mon, Object *obj, int indent); · line 105
Quoted 2 lines
qom/qom-hmp-cmds.c +0
-0static 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.
Quoted 2 lines
Reviewed-by Philippe Mathieu-Daudé <[email protected]>