All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thomas Huth <thuth@redhat.com>
To: qemu-devel@nongnu.org, Peter Maydell <peter.maydell@linaro.org>
Cc: Alexander Bulekov <alxndr@bu.edu>
Subject: [PULL 01/31] tests/migration: fix memleak in wait_command/wait_command_fd
Date: Mon, 26 Oct 2020 11:06:02 +0100	[thread overview]
Message-ID: <20201026100632.212530-2-thuth@redhat.com> (raw)
In-Reply-To: <20201026100632.212530-1-thuth@redhat.com>

From: Chen Qun <kuhn.chenqun@huawei.com>

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>
Message-Id: <20201023061218.2080844-2-kuhn.chenqun@huawei.com>
Signed-off-by: Thomas Huth <thuth@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;
 }
 
 /*
-- 
2.18.2



  reply	other threads:[~2020-10-26 10:08 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-26 10:06 [PULL 00/31] qtests and gitlab-CI/acceptance patches Thomas Huth
2020-10-26 10:06 ` Thomas Huth [this message]
2020-10-26 10:06 ` [PULL 02/31] tests/qtest/libqtest: Fix detection of architecture for binaries without path Thomas Huth
2020-10-26 10:06 ` [PULL 03/31] accel: Remove _WIN32 ifdef from qtest-cpus.c Thomas Huth
2020-10-26 10:06 ` [PULL 04/31] accel: move qtest CpusAccel functions to a common location Thomas Huth
2020-10-26 10:06 ` [PULL 05/31] accel: Add xen CpusAccel using dummy-cpus Thomas Huth
2020-10-26 10:06 ` [PULL 06/31] tests/qtest: Make npcm7xx_timer-test conditional on CONFIG_NPCM7XX Thomas Huth
2020-10-26 10:06 ` [PULL 07/31] libqtest: fix the order of buffered events Thomas Huth
2020-10-26 10:06 ` [PULL 08/31] libqtest: fix memory leak in the qtest_qmp_event_ref Thomas Huth
2020-10-26 10:06 ` [PULL 09/31] memory: Add FlatView foreach function Thomas Huth
2020-10-26 10:06 ` [PULL 10/31] fuzz: Add generic virtual-device fuzzer Thomas Huth
2020-10-26 10:06 ` [PULL 11/31] fuzz: Add PCI features to the generic fuzzer Thomas Huth
2020-10-26 10:06 ` [PULL 12/31] fuzz: Add DMA support to the generic-fuzzer Thomas Huth
2020-10-26 10:06 ` [PULL 13/31] fuzz: Declare DMA Read callback function Thomas Huth
2020-10-26 10:06 ` [PULL 14/31] fuzz: Add fuzzer callbacks to DMA-read functions Thomas Huth
2020-10-26 10:06 ` [PULL 15/31] fuzz: Add support for custom crossover functions Thomas Huth
2020-10-26 10:06 ` [PULL 16/31] fuzz: add a DISABLE_PCI op to generic-fuzzer Thomas Huth
2020-10-26 10:06 ` [PULL 17/31] fuzz: add a crossover function " Thomas Huth
2020-10-26 10:06 ` [PULL 18/31] scripts/oss-fuzz: Add script to reorder a generic-fuzzer trace Thomas Huth
2020-10-26 10:06 ` [PULL 19/31] scripts/oss-fuzz: Add crash trace minimization script Thomas Huth
2020-10-26 10:06 ` [PULL 20/31] fuzz: Add instructions for using generic-fuzz Thomas Huth
2020-10-26 10:06 ` [PULL 21/31] fuzz: add an "opaque" to the FuzzTarget struct Thomas Huth
2020-10-26 10:06 ` [PULL 22/31] fuzz: add generic-fuzz configs for oss-fuzz Thomas Huth
2020-10-26 10:06 ` [PULL 23/31] fuzz: register predefined generic-fuzz configs Thomas Huth
2020-10-26 10:06 ` [PULL 24/31] scripts/oss-fuzz: use hardlinks instead of copying Thomas Huth
2020-10-26 10:06 ` [PULL 25/31] scripts/oss-fuzz: ignore the generic-fuzz target Thomas Huth
2020-10-26 10:06 ` [PULL 26/31] tests/acceptance/ppc_prep_40p: Fix the URL to the NetBSD-4.0 archive Thomas Huth
2020-10-26 10:06 ` [PULL 27/31] test/acceptance: Remove the CONTINUOUS_INTEGRATION tags Thomas Huth
2020-10-26 10:06 ` [PULL 28/31] tests/acceptance: Enable AVOCADO_ALLOW_UNTRUSTED_CODE in the gitlab-CI Thomas Huth
2020-10-26 10:06 ` [PULL 29/31] test/docker/dockerfiles: Add missing packages for acceptance tests Thomas Huth
2020-10-26 10:06 ` [PULL 30/31] tests/acceptance: Remove unused import Thomas Huth
2020-10-26 10:06 ` [PULL 31/31] tests/acceptance: Use .ppm extention for Portable PixMap files Thomas Huth
2020-10-26 14:49 ` [PULL 00/31] qtests and gitlab-CI/acceptance patches Peter Maydell

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=20201026100632.212530-2-thuth@redhat.com \
    --to=thuth@redhat.com \
    --cc=alxndr@bu.edu \
    --cc=peter.maydell@linaro.org \
    --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.