From nobody Thu Nov 13 20:44:01 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=1582766139; cv=none; d=zohomail.com; s=zohoarc; b=C80tOmkY3kXthEHf18pPWizLsAAHgP8P4nPambQjTh7BXSYb/hEghqXihaCkYVtvH+fbku0Qwrk/wUhZ1WkrisrC0qc3n2hMZVy8FdZWhdF/kxSy2dc8hvvviQyB0Ug5EUksKB01qbwLxr2h3UfSt37SbfAVpiN3GHvbqOt6eVo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582766139; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=vAeBlI3OTRd0PdVNDjpyUkcKnkoUgKJFesqiFQmrOoA=; b=dQ4FAqlUFD3MkndoByN5TeKWImwH/vRL/aZNrudy4dS/rA1OZhTKhrlI474ic0UjSJZRSeW+HChvMyvbeZCakgNtF4LrQa4x3YNGal//EVVJjEvkCrIq9ke6Zc8CBjOB8/kyFQON2dtHAiFyJYs1oCN9U1D5/vPKJaHzypAdgM8= 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 15827661394101.527061177429914; Wed, 26 Feb 2020 17:15:39 -0800 (PST) Received: from localhost ([::1]:52408 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j77m5-0003Mz-KD for importer@patchew.org; Wed, 26 Feb 2020 20:15:37 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:48790) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j77l5-0002NE-5C for qemu-devel@nongnu.org; Wed, 26 Feb 2020 20:14:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j77l4-0006C4-1U for qemu-devel@nongnu.org; Wed, 26 Feb 2020 20:14:35 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:44974 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j77l0-0005wy-PU; Wed, 26 Feb 2020 20:14:31 -0500 Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 1EA7F4290A3AA0A2ED32; Thu, 27 Feb 2020 09:14:25 +0800 (CST) Received: from localhost.localdomain (10.175.104.216) by DGGEMS402-HUB.china.huawei.com (10.3.19.202) with Microsoft SMTP Server id 14.3.439.0; Thu, 27 Feb 2020 09:14:19 +0800 From: Pan Nengyuan To: , Subject: [PATCH v2 1/2] block/qcow2: do free crypto_opts in qcow2_close() Date: Thu, 27 Feb 2020 09:29:49 +0800 Message-ID: <20200227012950.12256-2-pannengyuan@huawei.com> X-Mailer: git-send-email 2.18.2 In-Reply-To: <20200227012950.12256-1-pannengyuan@huawei.com> References: <20200227012950.12256-1-pannengyuan@huawei.com> 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.35 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: euler.robot@huawei.com, Pan Nengyuan , qemu-devel@nongnu.org, qemu-block@nongnu.org, zhang.zhanghailiang@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" 'crypto_opts' forgot to free in qcow2_close(), this patch fix the bellow le= ak stack: Direct leak of 24 byte(s) in 1 object(s) allocated from: #0 0x7f0edd81f970 in __interceptor_calloc (/lib64/libasan.so.5+0xef970) #1 0x7f0edc6d149d in g_malloc0 (/lib64/libglib-2.0.so.0+0x5249d) #2 0x55d7eaede63d in qobject_input_start_struct /mnt/sdb/qemu-new/qemu_= test/qemu/qapi/qobject-input-visitor.c:295 #3 0x55d7eaed78b8 in visit_start_struct /mnt/sdb/qemu-new/qemu_test/qem= u/qapi/qapi-visit-core.c:49 #4 0x55d7eaf5140b in visit_type_QCryptoBlockOpenOptions qapi/qapi-visit= -crypto.c:290 #5 0x55d7eae43af3 in block_crypto_open_opts_init /mnt/sdb/qemu-new/qemu= _test/qemu/block/crypto.c:163 #6 0x55d7eacd2924 in qcow2_update_options_prepare /mnt/sdb/qemu-new/qem= u_test/qemu/block/qcow2.c:1148 #7 0x55d7eacd33f7 in qcow2_update_options /mnt/sdb/qemu-new/qemu_test/q= emu/block/qcow2.c:1232 #8 0x55d7eacd9680 in qcow2_do_open /mnt/sdb/qemu-new/qemu_test/qemu/blo= ck/qcow2.c:1512 #9 0x55d7eacdc55e in qcow2_open_entry /mnt/sdb/qemu-new/qemu_test/qemu/= block/qcow2.c:1792 #10 0x55d7eacdc8fe in qcow2_open /mnt/sdb/qemu-new/qemu_test/qemu/block= /qcow2.c:1819 #11 0x55d7eac3742d in bdrv_open_driver /mnt/sdb/qemu-new/qemu_test/qemu= /block.c:1317 #12 0x55d7eac3e990 in bdrv_open_common /mnt/sdb/qemu-new/qemu_test/qemu= /block.c:1575 #13 0x55d7eac4442c in bdrv_open_inherit /mnt/sdb/qemu-new/qemu_test/qem= u/block.c:3126 #14 0x55d7eac45c3f in bdrv_open /mnt/sdb/qemu-new/qemu_test/qemu/block.= c:3219 #15 0x55d7ead8e8a4 in blk_new_open /mnt/sdb/qemu-new/qemu_test/qemu/blo= ck/block-backend.c:397 #16 0x55d7eacde74c in qcow2_co_create /mnt/sdb/qemu-new/qemu_test/qemu/= block/qcow2.c:3534 #17 0x55d7eacdfa6d in qcow2_co_create_opts /mnt/sdb/qemu-new/qemu_test/= qemu/block/qcow2.c:3668 #18 0x55d7eac1c678 in bdrv_create_co_entry /mnt/sdb/qemu-new/qemu_test/= qemu/block.c:485 #19 0x55d7eb0024d2 in coroutine_trampoline /mnt/sdb/qemu-new/qemu_test/= qemu/util/coroutine-ucontext.c:115 Reported-by: Euler Robot Signed-off-by: Pan Nengyuan Reviewed-by: Max Reitz --- block/qcow2.c | 1 + 1 file changed, 1 insertion(+) diff --git a/block/qcow2.c b/block/qcow2.c index 3c754f616b..f16e7f7782 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2606,6 +2606,7 @@ static void qcow2_close(BlockDriverState *bs) =20 qcrypto_block_free(s->crypto); s->crypto =3D NULL; + qapi_free_QCryptoBlockOpenOptions(s->crypto_opts); =20 g_free(s->unknown_header_fields); cleanup_unknown_header_ext(bs); --=20 2.18.2 From nobody Thu Nov 13 20:44:01 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=1582766222; cv=none; d=zohomail.com; s=zohoarc; b=UkkIx76jwxApmgN2nKqvwJ1/Wo3WiqE5LxOug4y3WvPIrrDGoLTlSgW8AycAHDaJgnRYwaYoRrqO8S9mCToENZEfhAGaGeuvL6dZBz1tVh5czibQKrsozvFTSXTVZR/0EYMJmn1/W+w7pZ6J0PCUk8v/9K9iqa+sOU8Xh4c7z0o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582766222; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=cNm1IY1COlmgieDmzzjoRyjuJa85qpY5o6CIzczdgaU=; b=m2Y13pxtjYlqOQjjxp+NC/hVq2flIsgoMawSm5nJHcHqkwYqb7B+0VpmGIyacAbKvMtgXYSZ+5x4gMy4Ke9KmO4MiMjY5F2MR9VHfaLXcc1eebeuB1idI3fai08eIDf5NKSIlkceSibm5AaD9WwMRynYFw39AiSQFhJ84+sdDbA= 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 1582766222836751.3219417195377; Wed, 26 Feb 2020 17:17:02 -0800 (PST) Received: from localhost ([::1]:52434 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j77nR-0004t3-NN for importer@patchew.org; Wed, 26 Feb 2020 20:17:01 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:48841) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j77l6-0002PH-VF for qemu-devel@nongnu.org; Wed, 26 Feb 2020 20:14:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j77l5-0006FL-UT for qemu-devel@nongnu.org; Wed, 26 Feb 2020 20:14:36 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:3251 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j77l3-00065Q-AO; Wed, 26 Feb 2020 20:14:33 -0500 Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 33615D38C180B85EAE82; Thu, 27 Feb 2020 09:14:30 +0800 (CST) Received: from localhost.localdomain (10.175.104.216) by DGGEMS402-HUB.china.huawei.com (10.3.19.202) with Microsoft SMTP Server id 14.3.439.0; Thu, 27 Feb 2020 09:14:20 +0800 From: Pan Nengyuan To: , Subject: [PATCH v2 2/2] qemu-img: free memory before re-assign Date: Thu, 27 Feb 2020 09:29:50 +0800 Message-ID: <20200227012950.12256-3-pannengyuan@huawei.com> X-Mailer: git-send-email 2.18.2 In-Reply-To: <20200227012950.12256-1-pannengyuan@huawei.com> References: <20200227012950.12256-1-pannengyuan@huawei.com> 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.191 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: euler.robot@huawei.com, Pan Nengyuan , qemu-devel@nongnu.org, qemu-block@nongnu.org, zhang.zhanghailiang@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" collect_image_check() is called twice in img_check(), the filename/format w= ill be alloced without free the original memory. It is not a big deal since the process will exit anyway, but seems like a c= lean code and it will remove the warning spotted by asan. Reported-by: Euler Robot Signed-off-by: Pan Nengyuan --- v2->v1: - Instead of freeing part of props in collect_image_check(), do discard the= old check object and allocate a new one in the caller to make more sense.(= suggested by Max Reitz) --- qemu-img.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/qemu-img.c b/qemu-img.c index 804630a368..a824b8576a 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -817,6 +817,8 @@ static int img_check(int argc, char **argv) check->corruptions_fixed); } =20 + qapi_free_ImageCheck(check); + check =3D g_new0(ImageCheck, 1); ret =3D collect_image_check(bs, check, filename, fmt, 0); =20 check->leaks_fixed =3D leaks_fixed; --=20 2.18.2