From nobody Thu Nov 13 23:42:04 2025 Delivered-To: importer@patchew.org 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; 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=1583744863; cv=none; d=zohomail.com; s=zohoarc; b=cjHjLS9XmPZZNAYSDI2CbnPFLZtlXXzGqv3O0VYHzfbuJ7QnguU5IINP81I7qgmKNhib5bR/ABNagnu7JZse77Ql7HxXvdoY8u5QesDM4x1aWpIY3BdTZj3AC0H3AJ/EAVYMWmshdihaYIophWQh6mEJhDSoZPD+GabBjHfWfRs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583744863; h=Content-Type:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=+IR6tQLlDkDd+H6eB8pkRv1lVxEgLKPmY5Xaxq4Mlp8=; b=d3vuIXH9+2Q/SFei7VYwSBxVZFP6N3biAmH7GfR+pPnsNc/czn4htdl8QI3cNaQvkRfHoIcngpUNlLkcusG0J5k7yqBOY6S7axPrhdM7ZkTcut4BEx/qRyAXQjqnpOIXDali1Yf/ILfCUnfLM2vJCmpxsy42kbO9rPqJxnrWGjU= 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 1583744863132849.2531424674157; Mon, 9 Mar 2020 02:07:43 -0700 (PDT) Received: from localhost ([::1]:39094 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jBENx-0002UG-BM for importer@patchew.org; Mon, 09 Mar 2020 05:07:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53629) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jBEN5-0001cv-5G for qemu-devel@nongnu.org; Mon, 09 Mar 2020 05:06:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jBEN4-0001UH-0g for qemu-devel@nongnu.org; Mon, 09 Mar 2020 05:06:46 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:50274 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jBEN3-0001Sj-Lu for qemu-devel@nongnu.org; Mon, 09 Mar 2020 05:06:45 -0400 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 5899E161FA5BD74F81AF; Mon, 9 Mar 2020 17:06:39 +0800 (CST) Received: from localhost.huawei.com (10.175.104.216) by DGGEMS405-HUB.china.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.487.0; Mon, 9 Mar 2020 17:06:31 +0800 From: Pan Nengyuan To: , , Subject: [PATCH] qom-qmp-cmds: fix two memleaks in qmp_object_add Date: Mon, 9 Mar 2020 17:22:12 +0800 Message-ID: <20200309092212.3249-1-pannengyuan@huawei.com> X-Mailer: git-send-email 2.18.2 MIME-Version: 1.0 X-Originating-IP: [10.175.104.216] X-CFilter-Loop: Reflected X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 45.249.212.32 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: zhang.zhanghailiang@huawei.com, Pan Nengyuan , qemu-devel@nongnu.org, euler.robot@huawei.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 'type/id' forgot to free in qmp_object_add, this patch fix that. The leak stack: Direct leak of 84 byte(s) in 6 object(s) allocated from: #0 0x7fe2a5ebf768 in __interceptor_malloc (/lib64/libasan.so.5+0xef768) #1 0x7fe2a5044445 in g_malloc (/lib64/libglib-2.0.so.0+0x52445) #2 0x7fe2a505dd92 in g_strdup (/lib64/libglib-2.0.so.0+0x6bd92) #3 0x56344954e692 in qmp_object_add /mnt/sdb/qemu-new/qemu_test/qemu/qo= m/qom-qmp-cmds.c:258 #4 0x563449960f5a in do_qmp_dispatch /mnt/sdb/qemu-new/qemu_test/qemu/q= api/qmp-dispatch.c:132 #5 0x563449960f5a in qmp_dispatch /mnt/sdb/qemu-new/qemu_test/qemu/qapi= /qmp-dispatch.c:175 #6 0x563449498a30 in monitor_qmp_dispatch /mnt/sdb/qemu-new/qemu_test/q= emu/monitor/qmp.c:145 #7 0x56344949a64f in monitor_qmp_bh_dispatcher /mnt/sdb/qemu-new/qemu_t= est/qemu/monitor/qmp.c:234 #8 0x563449a92a3a in aio_bh_call /mnt/sdb/qemu-new/qemu_test/qemu/util/= async.c:136 Direct leak of 54 byte(s) in 6 object(s) allocated from: #0 0x7fe2a5ebf768 in __interceptor_malloc (/lib64/libasan.so.5+0xef768) #1 0x7fe2a5044445 in g_malloc (/lib64/libglib-2.0.so.0+0x52445) #2 0x7fe2a505dd92 in g_strdup (/lib64/libglib-2.0.so.0+0x6bd92) #3 0x56344954e6c4 in qmp_object_add /mnt/sdb/qemu-new/qemu_test/qemu/qo= m/qom-qmp-cmds.c:267 #4 0x563449960f5a in do_qmp_dispatch /mnt/sdb/qemu-new/qemu_test/qemu/q= api/qmp-dispatch.c:132 #5 0x563449960f5a in qmp_dispatch /mnt/sdb/qemu-new/qemu_test/qemu/qapi= /qmp-dispatch.c:175 #6 0x563449498a30 in monitor_qmp_dispatch /mnt/sdb/qemu-new/qemu_test/q= emu/monitor/qmp.c:145 #7 0x56344949a64f in monitor_qmp_bh_dispatcher /mnt/sdb/qemu-new/qemu_t= est/qemu/monitor/qmp.c:234 #8 0x563449a92a3a in aio_bh_call /mnt/sdb/qemu-new/qemu_test/qemu/util/= async.c:136 Fixes: 5f07c4d60d091320186e7b0edaf9ed2cc16b2d1e Reported-by: Euler Robot Signed-off-by: Pan Nengyuan --- qom/qom-qmp-cmds.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qom/qom-qmp-cmds.c b/qom/qom-qmp-cmds.c index 49db926fcc..ac59ba1aa8 100644 --- a/qom/qom-qmp-cmds.c +++ b/qom/qom-qmp-cmds.c @@ -247,8 +247,8 @@ void qmp_object_add(QDict *qdict, QObject **ret_data, E= rror **errp) QDict *pdict; Visitor *v; Object *obj; - const char *type; - const char *id; + g_autofree const char *type =3D NULL; + g_autofree const char *id =3D NULL; =20 type =3D qdict_get_try_str(qdict, "qom-type"); if (!type) { --=20 2.18.2