From nobody Sun May 19 12:13:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1603283345; cv=none; d=zohomail.com; s=zohoarc; b=m+K90LI4X5IPpPuTtzSHBoTiyzKUvpuePXO75T3yhe3ireDie2sqhSld6nHfrEVSOh9h+/GofSKaKmh/EIzZy2z9kV51QhoqQ+SO9shXC+9ntCg2C7eTa/PBqbfdcX8si9YYXRHi6gIcZ88pChH5wtnTrSfKmiPwcoKaWzZKt3w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603283345; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=I73qkPrmwBgNMYTpWZT2bTfo/8dhld1JotaBQkVWfQ8=; b=Y1vGz+GUfVP9b5s9VUu8mWsDWSOjlxKAjBOXJfY9qraUYUjUB13Pr6yv5xH8gOzOcYmI6qU4nXYslUsom5rSFX2xRkRWish2VUTXvFnrcHBiT4NzDCg11c3MDdk79G3ejn07cipacS+dbQ+NxLVQweniY88ckOm2dWhwx5obXpU= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1603283345010815.8906077485788; Wed, 21 Oct 2020 05:29:05 -0700 (PDT) Received: from localhost ([::1]:38514 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kVDEm-0003a6-6x for importer@patchew.org; Wed, 21 Oct 2020 08:29:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43428) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kVDDT-0002s6-CD; Wed, 21 Oct 2020 08:27:43 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:41246 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kVDDO-0004XW-LZ; Wed, 21 Oct 2020 08:27:42 -0400 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 53D9A91BD3BA74942A1D; Wed, 21 Oct 2020 20:27:25 +0800 (CST) Received: from huawei.com (10.175.104.175) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.487.0; Wed, 21 Oct 2020 20:27:19 +0800 From: Chen Qun To: , Subject: [PATCH] tests/migration: fix memleak in wait_command/wait_command_fd Date: Wed, 21 Oct 2020 20:27:11 +0800 Message-ID: <20201021122711.2035765-1-kuhn.chenqun@huawei.com> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.104.175] X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=45.249.212.32; envelope-from=kuhn.chenqun@huawei.com; helo=huawei.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/21 08:27:26 X-ACL-Warn: Detected OS = Linux 3.11 and newer [fuzzy] X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, thuth@redhat.com, zhang.zhanghailiang@huawei.com, Euler Robot , mlevitsk@redhat.com, ganqixin@huawei.com, Chen Qun , pbonzini@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" 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-streame= r.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-hel= pers.c:108 #12 0x557bf3c44642 in check_migration_status ../tests/qtest/migration-h= elpers.c:124 #13 0x557bf3c447e7 in wait_for_migration_status ../tests/qtest/migratio= n-helpers.c:148 #14 0x557bf3c43b8f in test_migrate_auto_converge ../tests/qtest/migrati= on-test.c:1243 ...... SUMMARY: AddressSanitizer: 11670244 byte(s) leaked in 8422 allocation(s). Reported-by: Euler Robot Signed-off-by: Chen Qun --- 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-helper= s.c index b799dbafb7..202064e4fc 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, *val; =20 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 ch= ar *command, ...) g_assert(!qdict_haskey(resp, "error")); g_assert(qdict_haskey(resp, "return")); =20 - return qdict_get_qdict(resp, "return"); + val =3D qdict_get_qdict(resp, "return"); + qobject_ref(val); + qobject_unref(resp); + + return val; } =20 /* @@ -53,7 +57,7 @@ QDict *wait_command_fd(QTestState *who, int fd, const cha= r *command, ...) QDict *wait_command(QTestState *who, const char *command, ...) { va_list ap; - QDict *resp; + QDict *resp, *val; =20 va_start(ap, command); resp =3D 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")); =20 - return qdict_get_qdict(resp, "return"); + val =3D qdict_get_qdict(resp, "return"); + qobject_ref(val); + qobject_unref(resp); + + return val; } =20 /* --=20 2.27.0