From patchwork Wed Dec 9 02:56:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhukeqian X-Patchwork-Id: 11960181 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.7 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 E84D9C4361B for ; Wed, 9 Dec 2020 02:58:33 +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 44A9923888 for ; Wed, 9 Dec 2020 02:58:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 44A9923888 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]:39760 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kmpgW-0001BC-3t for qemu-devel@archiver.kernel.org; Tue, 08 Dec 2020 21:58:32 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:38482) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kmpfH-0000bw-JV; Tue, 08 Dec 2020 21:57:15 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:2990) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kmpfF-0002ka-2U; Tue, 08 Dec 2020 21:57:15 -0500 Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4CrMBg6Wc6zhpdK; Wed, 9 Dec 2020 10:56:27 +0800 (CST) Received: from DESKTOP-5IS4806.china.huawei.com (10.174.187.37) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.487.0; Wed, 9 Dec 2020 10:56:50 +0800 From: Keqian Zhu To: Peter Maydell , Igor Mammedov , Eduardo Habkost Subject: [PATCH] bugfix: hostmem: Free host_nodes list right after visited Date: Wed, 9 Dec 2020 10:56:48 +0800 Message-ID: <20201209025648.23068-1-zhukeqian1@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 MIME-Version: 1.0 X-Originating-IP: [10.174.187.37] X-CFilter-Loop: Reflected Received-SPF: pass client-ip=45.249.212.191; envelope-from=zhukeqian1@huawei.com; helo=szxga05-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_H2=-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: qemu-devel@nongnu.org, alex.chen@huawei.com, qemu-arm@nongnu.org, kuhn.chenqun@huawei.com, wanghaibin.wang@huawei.com, Keqian Zhu Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" In host_memory_backend_get_host_nodes, we build host_nodes list and output it to v (a StringOutputVisitor) but forget to free the list. This fixes the memory leak. The memory leak stack: ==qemu-kvm==209357==ERROR: LeakSanitizer: detected memory leaks Direct leak of 32 byte(s) in 2 object(s) allocated from: #0 0xfffe430e3393 in __interceptor_calloc (/lib64/libasan.so.4+0xd3393) ??:? #1 0xfffe41d58b9b in g_malloc0 (/lib64/libglib-2.0.so.0+0x58b9b) ??:? #2 0xaaac0cdb6e43 (/usr/libexec/qemu-kvm+0xe16e43) backends/hostmem.c:94 #3 0xaaac0d2edf83 (/usr/libexec/qemu-kvm+0x134df83) qom/object.c:1478 #4 0xaaac0c976513 (/usr/libexec/qemu-kvm+0x9d6513) hw/core/machine-qmp-cmds.c:312 #5 0xaaac0d2e980b (/usr/libexec/qemu-kvm+0x134980b) qom/object.c:1001 #6 0xaaac0c97779b (/usr/libexec/qemu-kvm+0x9d779b) hw/core/machine-qmp-cmds.c:328 (discriminator 1) #7 0xaaac0d26ed3f (/usr/libexec/qemu-kvm+0x12ced3f) qapi/qapi-commands-machine.c:327 #8 0xaaac0d43d647 (/usr/libexec/qemu-kvm+0x149d647) qapi/qmp-dispatch.c:147 #9 0xaaac0d21f74b (/usr/libexec/qemu-kvm+0x127f74b) monitor/qmp.c:120 #10 0xaaac0d22074b (/usr/libexec/qemu-kvm+0x128074b) monitor/qmp.c:209 (discriminator 4) #11 0xaaac0d4daefb (/usr/libexec/qemu-kvm+0x153aefb) util/async.c:117 #12 0xaaac0d4e30fb (/usr/libexec/qemu-kvm+0x15430fb) util/aio-posix.c:459 #13 0xaaac0d4dac8f (/usr/libexec/qemu-kvm+0x153ac8f) util/async.c:268 #14 0xfffe41d52a6b in g_main_context_dispatch (/lib64/libglib-2.0.so.0+0x52a6b) ??:? #15 0xaaac0d4e0e97 (/usr/libexec/qemu-kvm+0x1540e97) util/main-loop.c:218 #16 0xaaac0cd9bfa7 (/usr/libexec/qemu-kvm+0xdfbfa7) vl.c:1791 #17 0xaaac0c823bc3 (/usr/libexec/qemu-kvm+0x883bc3) vl.c:4473 #18 0xfffe40ab3ebf in __libc_start_main (/lib64/libc.so.6+0x23ebf) ??:? #19 0xaaac0c82ed5f (/usr/libexec/qemu-kvm+0x88ed5f) ??:? SUMMARY: AddressSanitizer: 32 byte(s) leaked in 2 allocation(s). Fixes: 4cf1b76bf1e2 (hostmem: add properties for NUMA memory policy) Reported-by: Euler Robot Signed-off-by: Keqian Zhu Tested-by: Chen Qun Reviewed-by: Igor Mammedov --- backends/hostmem.c | 1 + 1 file changed, 1 insertion(+) diff --git a/backends/hostmem.c b/backends/hostmem.c index 4bde00e8e7..9f9ac95edd 100644 --- a/backends/hostmem.c +++ b/backends/hostmem.c @@ -105,6 +105,7 @@ host_memory_backend_get_host_nodes(Object *obj, Visitor *v, const char *name, ret: visit_type_uint16List(v, name, &host_nodes, errp); + qapi_free_uint16List(host_nodes); } static void