From patchwork Fri Jan 15 07:56:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Gan Qixin X-Patchwork-Id: 12021795 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6DCD8C433E6 for ; Fri, 15 Jan 2021 08:00:13 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id ECEC5208BA for ; Fri, 15 Jan 2021 08:00:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org ECEC5208BA Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:46260 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l0K1i-0004f4-IQ for qemu-devel@archiver.kernel.org; Fri, 15 Jan 2021 03:00:10 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:57794) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l0K11-0003gq-2I; Fri, 15 Jan 2021 02:59:27 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:3289) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l0K0y-0007wZ-A5; Fri, 15 Jan 2021 02:59:26 -0500 Received: from DGGEMS409-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4DHD7H1Btyzl4xy; Fri, 15 Jan 2021 15:57:47 +0800 (CST) Received: from huawei.com (10.175.104.175) by DGGEMS409-HUB.china.huawei.com (10.3.19.209) with Microsoft SMTP Server id 14.3.498.0; Fri, 15 Jan 2021 15:59:00 +0800 From: Gan Qixin To: , Subject: [PATCH] qtest/npcm7xx_pwm-test: Fix memleak in pwm_qom_get Date: Fri, 15 Jan 2021 15:56:34 +0800 Message-ID: <20210115075634.717909-1-ganqixin@huawei.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Originating-IP: [10.175.104.175] X-CFilter-Loop: Reflected Received-SPF: pass client-ip=45.249.212.190; envelope-from=ganqixin@huawei.com; helo=szxga04-in.huawei.com 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_NONE=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: Laurent Vivier , Thomas Huth , zhang.zhanghailiang@huawei.com, Havard Skinnemoen , Tyrone Ting , Gan Qixin , Euler Robot , kuhn.chenqun@huawei.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" The pwm_qom_get function didn't free "response", which caused an indirect memory leak. So use qobject_unref() to fix it. ASAN shows memory leak stack: Indirect leak of 74160000 byte(s) in 18000 object(s) allocated from: #0 0x7f96e2f79d4e in __interceptor_calloc (/lib64/libasan.so.5+0x112d4e) #1 0x7f96e2d98a50 in g_malloc0 (/lib64/libglib-2.0.so.0+0x55a50) #2 0x556313112180 in qdict_new ../qobject/qdict.c:30 #3 0x556313115bca in parse_object ../qobject/json-parser.c:318 #4 0x556313117810 in parse_value ../qobject/json-parser.c:546 #5 0x556313117bda in json_parser_parse ../qobject/json-parser.c:580 #6 0x55631310fe67 in json_message_process_token ../qobject/json-streamer.c:92 #7 0x5563131210b7 in json_lexer_feed_char ../qobject/json-lexer.c:313 #8 0x556313121662 in json_lexer_feed ../qobject/json-lexer.c:350 #9 0x5563131101e9 in json_message_parser_feed ../qobject/json-streamer.c:121 #10 0x5563130cb81e in qmp_fd_receive ../tests/qtest/libqtest.c:614 #11 0x5563130cba2b in qtest_qmp_receive_dict ../tests/qtest/libqtest.c:636 #12 0x5563130cb939 in qtest_qmp_receive ../tests/qtest/libqtest.c:624 #13 0x5563130cbe0d in qtest_vqmp ../tests/qtest/libqtest.c:715 #14 0x5563130cc40f in qtest_qmp ../tests/qtest/libqtest.c:756 #15 0x5563130c5623 in pwm_qom_get ../tests/qtest/npcm7xx_pwm-test.c:180 #16 0x5563130c595e in pwm_get_duty ../tests/qtest/npcm7xx_pwm-test.c:210 #17 0x5563130c7529 in test_toggle ../tests/qtest/npcm7xx_pwm-test.c:447 Reported-by: Euler Robot Signed-off-by: Gan Qixin Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Havard Skinnemoen Reviewed-by: Hao Wu --- Cc: Havard Skinnemoen Cc: Tyrone Ting Cc: Thomas Huth Cc: Laurent Vivier --- tests/qtest/npcm7xx_pwm-test.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/qtest/npcm7xx_pwm-test.c b/tests/qtest/npcm7xx_pwm-test.c index 33fbdf5f54..63557d2c06 100644 --- a/tests/qtest/npcm7xx_pwm-test.c +++ b/tests/qtest/npcm7xx_pwm-test.c @@ -175,6 +175,7 @@ static int pwm_index(const PWM *pwm) static uint64_t pwm_qom_get(QTestState *qts, const char *path, const char *name) { QDict *response; + uint64_t val; g_test_message("Getting properties %s from %s", name, path); response = qtest_qmp(qts, "{ 'execute': 'qom-get'," @@ -182,7 +183,9 @@ static uint64_t pwm_qom_get(QTestState *qts, const char *path, const char *name) path, name); /* The qom set message returns successfully. */ g_assert_true(qdict_haskey(response, "return")); - return qnum_get_uint(qobject_to(QNum, qdict_get(response, "return"))); + val = qnum_get_uint(qobject_to(QNum, qdict_get(response, "return"))); + qobject_unref(response); + return val; } static uint64_t pwm_get_freq(QTestState *qts, int module_index, int pwm_index)