All of lore.kernel.org
 help / color / mirror / Atom feed
From: Li Qiang <liq3ea@163.com>
To: pbonzini@redhat.com, berrange@redhat.com, ehabkost@redhat.com,
	armbru@redhat.com
Cc: Li Qiang <liq3ea@163.com>, liq3ea@gmail.com, qemu-devel@nongnu.org
Subject: [PATCH] hmp: fix memory leak in qom_composition_compare()
Date: Tue, 14 Jul 2020 08:11:52 -0700	[thread overview]
Message-ID: <20200714151152.54760-1-liq3ea@163.com> (raw)

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



             reply	other threads:[~2020-07-14 15:12 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-14 15:11 Li Qiang [this message]
2020-07-14 16:47 ` [PATCH] hmp: fix memory leak in qom_composition_compare() Philippe Mathieu-Daudé
2020-07-14 17:20   ` Li Qiang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200714151152.54760-1-liq3ea@163.com \
    --to=liq3ea@163.com \
    --cc=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=liq3ea@gmail.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.