From: Igor Mammedov <imammedo@redhat.com>
To: Pan Nengyuan <pannengyuan@huawei.com>
Cc: berrange@redhat.com, ehabkost@redhat.com, qemu-devel@nongnu.org,
euler.robot@huawei.com, pbonzini@redhat.com,
zhang.zhanghailiang@huawei.com
Subject: Re: [PATCH] qom-qmp-cmds: fix two memleaks in qmp_object_add
Date: Mon, 9 Mar 2020 10:51:45 +0100 [thread overview]
Message-ID: <20200309105145.2f3f6a81@redhat.com> (raw)
In-Reply-To: <20200309092212.3249-1-pannengyuan@huawei.com>
On Mon, 9 Mar 2020 17:22:12 +0800
Pan Nengyuan <pannengyuan@huawei.com> wrote:
> 'type/id' forgot to free in qmp_object_add, this patch fix that.
>
> The leak stack:
> Direct leak of 84 byte(s) in 6 object(s) allocated from:
> #0 0x7fe2a5ebf768 in __interceptor_malloc (/lib64/libasan.so.5+0xef768)
> #1 0x7fe2a5044445 in g_malloc (/lib64/libglib-2.0.so.0+0x52445)
> #2 0x7fe2a505dd92 in g_strdup (/lib64/libglib-2.0.so.0+0x6bd92)
> #3 0x56344954e692 in qmp_object_add /mnt/sdb/qemu-new/qemu_test/qemu/qom/qom-qmp-cmds.c:258
> #4 0x563449960f5a in do_qmp_dispatch /mnt/sdb/qemu-new/qemu_test/qemu/qapi/qmp-dispatch.c:132
> #5 0x563449960f5a in qmp_dispatch /mnt/sdb/qemu-new/qemu_test/qemu/qapi/qmp-dispatch.c:175
> #6 0x563449498a30 in monitor_qmp_dispatch /mnt/sdb/qemu-new/qemu_test/qemu/monitor/qmp.c:145
> #7 0x56344949a64f in monitor_qmp_bh_dispatcher /mnt/sdb/qemu-new/qemu_test/qemu/monitor/qmp.c:234
> #8 0x563449a92a3a in aio_bh_call /mnt/sdb/qemu-new/qemu_test/qemu/util/async.c:136
>
> Direct leak of 54 byte(s) in 6 object(s) allocated from:
> #0 0x7fe2a5ebf768 in __interceptor_malloc (/lib64/libasan.so.5+0xef768)
> #1 0x7fe2a5044445 in g_malloc (/lib64/libglib-2.0.so.0+0x52445)
> #2 0x7fe2a505dd92 in g_strdup (/lib64/libglib-2.0.so.0+0x6bd92)
> #3 0x56344954e6c4 in qmp_object_add /mnt/sdb/qemu-new/qemu_test/qemu/qom/qom-qmp-cmds.c:267
> #4 0x563449960f5a in do_qmp_dispatch /mnt/sdb/qemu-new/qemu_test/qemu/qapi/qmp-dispatch.c:132
> #5 0x563449960f5a in qmp_dispatch /mnt/sdb/qemu-new/qemu_test/qemu/qapi/qmp-dispatch.c:175
> #6 0x563449498a30 in monitor_qmp_dispatch /mnt/sdb/qemu-new/qemu_test/qemu/monitor/qmp.c:145
> #7 0x56344949a64f in monitor_qmp_bh_dispatcher /mnt/sdb/qemu-new/qemu_test/qemu/monitor/qmp.c:234
> #8 0x563449a92a3a in aio_bh_call /mnt/sdb/qemu-new/qemu_test/qemu/util/async.c:136
>
> Fixes: 5f07c4d60d091320186e7b0edaf9ed2cc16b2d1e
> Reported-by: Euler Robot <euler.robot@huawei.com>
> Signed-off-by: Pan Nengyuan <pannengyuan@huawei.com>
> ---
> qom/qom-qmp-cmds.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/qom/qom-qmp-cmds.c b/qom/qom-qmp-cmds.c
> index 49db926fcc..ac59ba1aa8 100644
> --- a/qom/qom-qmp-cmds.c
> +++ b/qom/qom-qmp-cmds.c
> @@ -247,8 +247,8 @@ void qmp_object_add(QDict *qdict, QObject **ret_data, Error **errp)
> QDict *pdict;
> Visitor *v;
> Object *obj;
> - const char *type;
> - const char *id;
> + g_autofree const char *type = NULL;
> + g_autofree const char *id = NULL;
not sure that's it's correct
qdict_get_try_str() returns the reference to a string within
the QDict, so caller who provided qdict should take care of
freeing it.
>
> type = qdict_get_try_str(qdict, "qom-type");
> if (!type) {
next prev parent reply other threads:[~2020-03-09 9:53 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-09 9:22 [PATCH] qom-qmp-cmds: fix two memleaks in qmp_object_add Pan Nengyuan
2020-03-09 9:51 ` Igor Mammedov [this message]
2020-03-09 10:15 ` Daniel P. Berrangé
2020-03-09 10:22 ` Pan Nengyuan
2020-03-09 10:17 ` Pan Nengyuan
2020-03-09 10:06 ` Markus Armbruster
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=20200309105145.2f3f6a81@redhat.com \
--to=imammedo@redhat.com \
--cc=berrange@redhat.com \
--cc=ehabkost@redhat.com \
--cc=euler.robot@huawei.com \
--cc=pannengyuan@huawei.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=zhang.zhanghailiang@huawei.com \
/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 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).