qom-hmp-cmds: fix a memleak in hmp_qom_get
PATCH 1/1 qom-hmp-cmds: fix a memleak in hmp_qom_get
'obj' forgot to free at the end of hmp_qom_get(). Fix that.
The leak stack:
Direct leak of 40 byte(s) in 1 object(s) allocated from:
#0 0x7f4e3a779ae8 in __interceptor_malloc (/lib64/libasan.so.5+0xefae8)
#1 0x7f4e398f91d5 in g_malloc (/lib64/libglib-2.0.so.0+0x531d5)
#2 0x55c9fd9a3999 in qstring_from_substr /build/qemu/src/qobject/qstring.c:45
#3 0x55c9fd894bd3 in qobject_output_type_str /build/qemu/src/qapi/qobject-output-visitor.c:175
#4 0x55c9fd894bd3 in qobject_output_type_str /build/qemu/src/qapi/qobject-output-visitor.c:168
#5 0x55c9fd88b34d in visit_type_str /build/qemu/src/qapi/qapi-visit-core.c:308
#6 0x55c9fd59aa6b in property_get_str /build/qemu/src/qom/object.c:2064
#7 0x55c9fd5adb8a in object_property_get_qobject /build/qemu/src/qom/qom-qobject.c:38
#8 0x55c9fd4a029d in hmp_qom_get /build/qemu/src/qom/qom-hmp-cmds.c:66--- qom/qom-hmp-cmds.c | 1 + 1 file changed, 1 insertion(+)
qom/qom-hmp-cmds.c +1 -0
@@ -71,6 +71,7 @@ void hmp_qom_get(Monitor *mon, const QDict *qdict)qobject_unref (str); } +qobject_unref (obj);hmp_handle_error (mon, err); }
Signature · 1 line
2.18.2
Hi Pan,
Quoted 14 lines · Pan Nengyuan
'obj' forgot to free at the end of
hmp_qom_get(). Fix that.The leak stack:
Direct leak of 40 byte(s) in 1 object(s) allocated from:#0 0x7f4e3a779ae8 in __interceptor_malloc (/lib64/libasan.so.5+0xefae8) #1 0x7f4e398f91d5 in g_malloc (/lib64/libglib-2.0.so.0+0x531d5) #2 0x55c9fd9a3999 in qstring_from_substr /build/qemu/src/qobject/qstring.c:45 #3 0x55c9fd894bd3 in qobject_output_type_str /build/qemu/src/qapi/qobject-output-visitor.c:175 #4 0x55c9fd894bd3 in qobject_output_type_str /build/qemu/src/qapi/qobject-output-visitor.c:168 #5 0x55c9fd88b34d in visit_type_str /build/qemu/src/qapi/qapi-visit-core.c:308 #6 0x55c9fd59aa6b in property_get_str /build/qemu/src/qom/object.c:2064 #7 0x55c9fd5adb8a in object_property_get_qobject /build/qemu/src/qom/qom-qobject.c:38 #8 0x55c9fd4a029d in hmp_qom_get /build/qemu/src/qom/qom-hmp-cmds.c:66
Quoted 1 line
Fixes 89cf4fe34f4
When you fix a bug in a specific commit, please Cc the commit author and the reviewers, so they have a chance to 1/ review your fix and 2/ learn from their mistake.
Quoted 11 lines
Reported-by Euler Robot <[email protected]>Signed-off-by Pan Nengyuan <[email protected]>--- qom/qom-hmp-cmds.c | 1 + 1 file changed, 1 insertion(+)qom/qom-hmp-cmds.c +0
-0
qom/qom-hmp-cmds.c void hmp_qom_get(Monitor *mon, const QDict *qdict) · line 74
Quoted 4 lines
qom/qom-hmp-cmds.c +1
-0@@ -71,6 +71,7 @@ void hmp_qom_get(Monitor *mon, const QDict *qdict)qobject_unref (str); } +qobject_unref (obj);
The object_resolve_path() documentation is not clear about that... Can we get the documentation clarified?
Quoted 4 lines
qom/qom-hmp-cmds.c +0
-0hmp_handle_error (mon, err); }
Quoted 17 lines · Philippe Mathieu-Daudé
Hi Pan,
Quoted 14 lines · Pan Nengyuan
'obj' forgot to free at the end of
hmp_qom_get(). Fix that.The leak stack:
Direct leak of 40 byte(s) in 1 object(s) allocated from:#0 0x7f4e3a779ae8 in __interceptor_malloc (/lib64/libasan.so.5+0xefae8) #1 0x7f4e398f91d5 in g_malloc (/lib64/libglib-2.0.so.0+0x531d5) #2 0x55c9fd9a3999 in qstring_from_substr /build/qemu/src/qobject/qstring.c:45 #3 0x55c9fd894bd3 in qobject_output_type_str /build/qemu/src/qapi/qobject-output-visitor.c:175 #4 0x55c9fd894bd3 in qobject_output_type_str /build/qemu/src/qapi/qobject-output-visitor.c:168 #5 0x55c9fd88b34d in visit_type_str /build/qemu/src/qapi/qapi-visit-core.c:308 #6 0x55c9fd59aa6b in property_get_str /build/qemu/src/qom/object.c:2064 #7 0x55c9fd5adb8a in object_property_get_qobject /build/qemu/src/qom/qom-qobject.c:38 #8 0x55c9fd4a029d in hmp_qom_get /build/qemu/src/qom/qom-hmp-cmds.c:66
Quoted 5 lines
Quoted 1 line
Fixes 89cf4fe34f4When you fix a bug in a specific commit, please Cc the commit author and the reviewers, so they have a chance to 1/ review your fix and 2/ learn from their mistake.
Ok, I will do next time.
Quoted 15 lines
Quoted 15 lines
Reported-by Euler Robot <[email protected]>Signed-off-by Pan Nengyuan <[email protected]>--- qom/qom-hmp-cmds.c | 1 + 1 file changed, 1 insertion(+)qom/qom-hmp-cmds.c +0
-0@@ -71,6 +71,7 @@ void hmp_qom_get(Monitor *mon, const QDict *qdict)qobject_unref (str); }
Quoted 4 lines
qom/qom-hmp-cmds.c void hmp_qom_get(Monitor *mon, const QDict *qdict) · line 74
Quoted 1 line
qom/qom-hmp-cmds.c +1
-0+qobject_unref (obj);The
object_resolve_path()documentation is not clear about that... Can we get the documentation clarified?
I'm not sure why is object_resolve_path().
In this case, 'obj' is returned from object_property_get_qobject() in qmp_qom_get().
Do you mean document object_property_get_qobject() to make it more clear?
Like:
- The returned object has a reference count of 1, and will be freed when the last reference is dropped.
Thanks.
Quoted 6 lines
Quoted 5 lines
qom/qom-hmp-cmds.c +0
-0hmp_handle_error (mon, err); }
Quoted 19 lines · Pan Nengyuan <[email protected]> 于2020年6月3日周三 下午2:17写道:
'obj' forgot to free at the end of
hmp_qom_get(). Fix that.The leak stack:
Direct leak of 40 byte(s) in 1 object(s) allocated from:#0 0x7f4e3a779ae8 in __interceptor_malloc (/lib64/libasan.so.5+0xefae8) #1 0x7f4e398f91d5 in g_malloc (/lib64/libglib-2.0.so.0+0x531d5) #2 0x55c9fd9a3999 in qstring_from_substr /build/qemu/src/qobject/qstring.c:45 #3 0x55c9fd894bd3 in qobject_output_type_str /build/qemu/src/qapi/qobject-output-visitor.c:175 #4 0x55c9fd894bd3 in qobject_output_type_str /build/qemu/src/qapi/qobject-output-visitor.c:168 #5 0x55c9fd88b34d in visit_type_str /build/qemu/src/qapi/qapi-visit-core.c:308 #6 0x55c9fd59aa6b in property_get_str /build/qemu/src/qom/object.c:2064 #7 0x55c9fd5adb8a in object_property_get_qobject /build/qemu/src/qom/qom-qobject.c:38 #8 0x55c9fd4a029d in hmp_qom_get /build/qemu/src/qom/qom-hmp-cmds.c:66
Quoted 4 lines
Fixes 89cf4fe34f4Reported-by Euler Robot <[email protected]>Signed-off-by Pan Nengyuan <[email protected]>
This can be tested by compile qemu with '-fsanitize=address' cflags and:
make check
Li Qiang
Quoted 21 lines
--- qom/qom-hmp-cmds.c | 1 + 1 file changed, 1 insertion(+)qom/qom-hmp-cmds.c +1
-1@@ -71,6 +71,7 @@ void hmp_qom_get(Monitor *mon, const QDict *qdict)qobject_unref (str); } +qobject_unref (obj);hmp_handle_error (mon, err); } --2.18.2
Quoted 14 lines · * Pan Nengyuan ([email protected]) wrote:
'obj' forgot to free at the end of
hmp_qom_get(). Fix that.The leak stack:
Direct leak of 40 byte(s) in 1 object(s) allocated from:#0 0x7f4e3a779ae8 in __interceptor_malloc (/lib64/libasan.so.5+0xefae8) #1 0x7f4e398f91d5 in g_malloc (/lib64/libglib-2.0.so.0+0x531d5) #2 0x55c9fd9a3999 in qstring_from_substr /build/qemu/src/qobject/qstring.c:45 #3 0x55c9fd894bd3 in qobject_output_type_str /build/qemu/src/qapi/qobject-output-visitor.c:175 #4 0x55c9fd894bd3 in qobject_output_type_str /build/qemu/src/qapi/qobject-output-visitor.c:168 #5 0x55c9fd88b34d in visit_type_str /build/qemu/src/qapi/qapi-visit-core.c:308 #6 0x55c9fd59aa6b in property_get_str /build/qemu/src/qom/object.c:2064 #7 0x55c9fd5adb8a in object_property_get_qobject /build/qemu/src/qom/qom-qobject.c:38 #8 0x55c9fd4a029d in hmp_qom_get /build/qemu/src/qom/qom-hmp-cmds.c:66
Quoted 3 lines
Fixes 89cf4fe34f4Reported-by Euler Robot <[email protected]>Signed-off-by Pan Nengyuan <[email protected]>
Queued.
Quoted 20 lines
--- qom/qom-hmp-cmds.c | 1 + 1 file changed, 1 insertion(+)qom/qom-hmp-cmds.c +1
-0@@ -71,6 +71,7 @@ void hmp_qom_get(Monitor *mon, const QDict *qdict)qobject_unref (str); } +qobject_unref (obj);hmp_handle_error (mon, err); }Signature · 1 line
2.18.2
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK