qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Maxim Levitsky <mlevitsk@redhat.com>
To: Chen Qun <kuhn.chenqun@huawei.com>,
	qemu-devel@nongnu.org,  qemu-trivial@nongnu.org
Cc: lvivier@redhat.com, Thomas Huth <thuth@redhat.com>,
	zhang.zhanghailiang@huawei.com, pannengyuan@huawei.com,
	ganqixin@huawei.com, Euler Robot <euler.robot@huawei.com>,
	Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [PATCH RESEND v2 1/7] tests/migration: fix memleak in wait_command/wait_command_fd
Date: Mon, 26 Oct 2020 11:51:09 +0200	[thread overview]
Message-ID: <f90ddef4bccccb5b7edf8417e4b4e0898021d88e.camel@redhat.com> (raw)
In-Reply-To: <20201023061218.2080844-2-kuhn.chenqun@huawei.com>

On Fri, 2020-10-23 at 14:12 +0800, Chen Qun wrote:
> Properly free each command resp to avoid memory leak.
> ASAN shows memory leak stack:
> 
> Indirect leak of 2352520 byte(s) in 571 object(s) allocated from:
>     #0 0x7f6ca3308d4e in __interceptor_calloc (/lib64/libasan.so.5+0x112d4e)
>     #1 0x7f6ca3127a50 in g_malloc0 (/lib64/libglib-2.0.so.0+0x55a50)
>     #2 0x557bf3c71d2b in qdict_new ../qobject/qdict.c:29
>     #3 0x557bf3c9caba in parse_object ../qobject/json-parser.c:318
>     #4 0x557bf3c9ce75 in json_parser_parse ../qobject/json-parser.c:580
>     #5 0x557bf3c8c8cf in json_message_process_token ../qobject/json-streamer.c:92
>     #6 0x557bf3c9ea59 in json_lexer_feed_char ../qobject/json-lexer.c:313
>     #7 0x557bf3c9eeb5 in json_lexer_feed ../qobject/json-lexer.c:350
>     #8 0x557bf3c4793a in qmp_fd_receive ../tests/qtest/libqtest.c:608
>     #9 0x557bf3c47b58 in qtest_qmp_receive ../tests/qtest/libqtest.c:618
>     #10 0x557bf3c44245 in wait_command ../tests/qtest/migration-helpers.c:59
>     #11 0x557bf3c445cb in migrate_query_status ../tests/qtest/migration-helpers.c:108
>     #12 0x557bf3c44642 in check_migration_status ../tests/qtest/migration-helpers.c:124
>     #13 0x557bf3c447e7 in wait_for_migration_status ../tests/qtest/migration-helpers.c:148
>     #14 0x557bf3c43b8f in test_migrate_auto_converge ../tests/qtest/migration-test.c:1243
>     ......
> 
> Fix: 5e34005571af5
> 
> Reported-by: Euler Robot <euler.robot@huawei.com>
> Signed-off-by: Chen Qun <kuhn.chenqun@huawei.com>
> ---
> Cc: Thomas Huth <thuth@redhat.com>
> Cc: Laurent Vivier <lvivier@redhat.com>
> Cc: Maxim Levitsky <mlevitsk@redhat.com>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  tests/qtest/migration-helpers.c | 16 ++++++++++++----
>  1 file changed, 12 insertions(+), 4 deletions(-)
> 
> diff --git a/tests/qtest/migration-helpers.c b/tests/qtest/migration-helpers.c
> index b799dbafb7..4ee26014b7 100644
> --- a/tests/qtest/migration-helpers.c
> +++ b/tests/qtest/migration-helpers.c
> @@ -32,7 +32,7 @@ static void check_stop_event(QTestState *who)
>  QDict *wait_command_fd(QTestState *who, int fd, const char *command, ...)
>  {
>      va_list ap;
> -    QDict *resp;
> +    QDict *resp, *ret;
>  
>      va_start(ap, command);
>      qtest_qmp_vsend_fds(who, &fd, 1, command, ap);
> @@ -44,7 +44,11 @@ QDict *wait_command_fd(QTestState *who, int fd, const char *command, ...)
>      g_assert(!qdict_haskey(resp, "error"));
>      g_assert(qdict_haskey(resp, "return"));
>  
> -    return qdict_get_qdict(resp, "return");
> +    ret = qdict_get_qdict(resp, "return");
> +    qobject_ref(ret);
> +    qobject_unref(resp);
> +
> +    return ret;
>  }
>  
>  /*
> @@ -53,7 +57,7 @@ QDict *wait_command_fd(QTestState *who, int fd, const char *command, ...)
>  QDict *wait_command(QTestState *who, const char *command, ...)
>  {
>      va_list ap;
> -    QDict *resp;
> +    QDict *resp, *ret;
>  
>      va_start(ap, command);
>      resp = qtest_vqmp(who, command, ap);
> @@ -64,7 +68,11 @@ QDict *wait_command(QTestState *who, const char *command, ...)
>      g_assert(!qdict_haskey(resp, "error"));
>      g_assert(qdict_haskey(resp, "return"));
>  
> -    return qdict_get_qdict(resp, "return");
> +    ret = qdict_get_qdict(resp, "return");
> +    qobject_ref(ret);
> +    qobject_unref(resp);
> +
> +    return ret;
>  }
>  
>  /*
This is a funny one. I was thinking that reference counters in qobject should take care of this.
I guess not.

Thanks for fixing it.

Best regards,
	Maxim Levitsky




  parent reply	other threads:[~2020-10-26  9:53 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-23  6:12 [PATCH RESEND v2 0/7] some memleak trivial patchs Chen Qun
2020-10-23  6:12 ` [PATCH RESEND v2 1/7] tests/migration: fix memleak in wait_command/wait_command_fd Chen Qun
2020-10-23  6:34   ` Thomas Huth
2020-10-26  9:51   ` Maxim Levitsky [this message]
2020-10-23  6:12 ` [PATCH RESEND v2 2/7] qga/channel-posix: Plug memory leak in ga_channel_write_all() Chen Qun
2020-12-14  2:04   ` Chenqun (kuhn)
2020-10-23  6:12 ` [PATCH RESEND v2 3/7] elf2dmp/qemu_elf: Plug memleak in QEMU_Elf_init Chen Qun
2020-10-23  7:22   ` Thomas Huth
2020-12-13 17:44   ` Laurent Vivier
2020-12-14  2:26     ` Chenqun (kuhn)
2020-10-23  6:12 ` [PATCH RESEND v2 4/7] elf2dmp/pdb: Plug memleak in pdb_init_from_file Chen Qun
2020-10-23  7:22   ` Thomas Huth
2020-12-13 17:44   ` Laurent Vivier
2020-10-23  6:12 ` [PATCH RESEND v2 5/7] migration/colo: Plug memleaks in colo_process_incoming_thread Chen Qun
2020-12-14  3:12   ` Chenqun (kuhn)
2020-10-23  6:12 ` [PATCH RESEND v2 6/7] blockdev: Fix a memleak in drive_backup_prepare() Chen Qun
2020-12-13 17:50   ` Laurent Vivier
2020-10-23  6:12 ` [PATCH RESEND v2 7/7] block/file-posix: fix a possible undefined behavior Chen Qun
2020-12-13 17:46   ` Laurent Vivier
2020-10-30 10:23 ` [PATCH RESEND v2 0/7] some memleak trivial patchs Chenqun (kuhn)
2020-11-04  5:49 ` Chenqun (kuhn)
2020-12-09  2:48 ` Chenqun (kuhn)

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=f90ddef4bccccb5b7edf8417e4b4e0898021d88e.camel@redhat.com \
    --to=mlevitsk@redhat.com \
    --cc=euler.robot@huawei.com \
    --cc=ganqixin@huawei.com \
    --cc=kuhn.chenqun@huawei.com \
    --cc=lvivier@redhat.com \
    --cc=pannengyuan@huawei.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-trivial@nongnu.org \
    --cc=thuth@redhat.com \
    --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).