From nobody Mon Feb 9 16:02:30 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1619799937; cv=none; d=zohomail.com; s=zohoarc; b=n7GYI9JL4tELKvqkA0wVpn+rIplimGSgAtjCysmoqH9ei4+Gl+5XfGp1yNXN88YXixVFkoDWXvuUdqZHrB2wkqVJkW0BBW0Xqv6ajoVm8Kehhx1wM9UP+9n5cJBLfEkKbCmgSyxukBAUh00LORpiyXhSRvJ2ugmx45f7uHUeUI8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619799937; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=Q0q+PVZkRpHjkgV8Clf4ufwkVBb96ymjjweCH0oDKVY=; b=Rf8Et2eyNUaEo1tvMoZST7fA1t0mFFt6mhJuHhOxQh0XcfItZCMmNg5xoG/p6mtn1raiZJse5UCiJ3vp6SIzBWVdc8IaA3EM2FvMnEYhW7Z81yCJGmPBzH3+QW64Kl0aFh8IKAbRpdkSwk3GPD6RzsHKZ5TbflJ6go1tgrN1zWo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 16197999379161023.3592787926959; Fri, 30 Apr 2021 09:25:37 -0700 (PDT) Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-236-5_MB0kLnMn2OsQ282vXKfQ-1; Fri, 30 Apr 2021 12:25:33 -0400 Received: by mail-wr1-f71.google.com with SMTP id 67-20020adf81490000b029010756d109e6so14076781wrm.13 for ; Fri, 30 Apr 2021 09:25:32 -0700 (PDT) Return-Path: Return-Path: Received: from localhost.localdomain (anancy-651-1-208-144.w109-217.abo.wanadoo.fr. [109.217.237.144]) by smtp.gmail.com with ESMTPSA id a15sm2828323wrr.53.2021.04.30.09.25.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Apr 2021 09:25:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619799936; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Q0q+PVZkRpHjkgV8Clf4ufwkVBb96ymjjweCH0oDKVY=; b=bem13bl6HlAjmOl+KssN5l/bdcZexSbrjbnCju/2UjnE8xlxgGYz9Dk2NgLRo3uRXZlMDm G34p2/X5ZC4WK3Ja/pWgbCEgR4JkWgRTDAkASpBCjbJgM0/SOU4uB0wuVZsfaiEFJjC4nu AmhDnoYQNHJMn6pzDPCflY8DFt2oM+c= X-MC-Unique: 5_MB0kLnMn2OsQ282vXKfQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Q0q+PVZkRpHjkgV8Clf4ufwkVBb96ymjjweCH0oDKVY=; b=mUa1qcPc46BZcMb/yCLZetuKBqvpEk1IDSNQ2WKVlxMF40kXHrHSemHrzNEwJ0YX8J hOF+wuE7BiZCkyRCxbGMYoKcx98k5V2WgCRtvc1GHJi8WNbE9XnpBeuAu01jwIBISnKn K0BUzfMc0qMG3GljrlxTGXw+Wf63tZbbbUDGpBkcwUZGAFUGi53jSVHso/fIbiXupGXE OBK6i6P3cXqWtBiWuXJxvk/VYh/LUI7iOmdVMOms15uYNEuoCYyObMeU3Teh7FZNquG3 Rz7M1EzCJFA/K+HpBBcTlk1JQlcv9n0VTkT0nflNbNsyKF3OuV+7lsW7z1CCMPfToU1u RueQ== X-Gm-Message-State: AOAM5303Vw6H3Cnq9Mpk8itHQIdOXOA1CxH+53ImUsBhrVu0ywr8RYmr xROP8F2C5Fcha8VRLu1G7AQ2+AXMYRkT16FfDPHKWZmdWQ+GfMkFmPi1dA9COD+3dAHYR7dRR2k Gc7mBhxDtwj6bGw== X-Received: by 2002:a05:6000:1084:: with SMTP id y4mr8215923wrw.364.1619799931913; Fri, 30 Apr 2021 09:25:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzWvd94iWDs7QWXEsbG9ptXDumLhtGDra5yu/nrAB5VmX50YwVihrIOgL3ZDYwaYGvLa3gxOg== X-Received: by 2002:a05:6000:1084:: with SMTP id y4mr8215911wrw.364.1619799931800; Fri, 30 Apr 2021 09:25:31 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Max Reitz , Kevin Wolf , Johannes Schindelin , qemu-block@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH 2/4] block/vvfat: Fix leak of BDRVVVFATState::used_clusters Date: Fri, 30 Apr 2021 18:25:17 +0200 Message-Id: <20210430162519.271607-3-philmd@redhat.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210430162519.271607-1-philmd@redhat.com> References: <20210430162519.271607-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) used_clusters is allocated in enable_write_target(), called by vvfat_open(), but never free'd. Allocate it using GLib API, and free it in vvfat_close(). This fixes (QEMU built with --enable-sanitizers): Direct leak of 64508 byte(s) in 1 object(s) allocated from: #0 0x55d7a36378f7 in calloc (qemu-system-x86_64+0x1dab8f7) #1 0x55d7a5e14246 in enable_write_target block/vvfat.c:3145:24 #2 0x55d7a5e123aa in vvfat_open block/vvfat.c:1236:19 #3 0x55d7a5a5363f in bdrv_open_driver block.c:1526:15 #4 0x55d7a5a9d369 in bdrv_open_common block.c:1802:11 #5 0x55d7a5a609f1 in bdrv_open_inherit block.c:3444:11 #6 0x55d7a5a65411 in bdrv_open_child_bs block.c:3079:10 #7 0x55d7a5a60079 in bdrv_open_inherit block.c:3391:19 #8 0x55d7a5a65da3 in bdrv_open block.c:3537:12 #9 0x55d7a5b33f6a in blk_new_open block/block-backend.c:421:10 #10 0x55d7a5a0a33e in blockdev_init blockdev.c:610:15 #11 0x55d7a5a088e7 in drive_new blockdev.c:994:11 #12 0x55d7a51b10c4 in drive_init_func softmmu/vl.c:636:12 #13 0x55d7a620e148 in qemu_opts_foreach util/qemu-option.c:1167:14 #14 0x55d7a51b0e20 in configure_blockdev softmmu/vl.c:695:9 #15 0x55d7a51a70b5 in qemu_create_early_backends softmmu/vl.c:1895:5 #16 0x55d7a519bf87 in qemu_init softmmu/vl.c:3551:5 #17 0x55d7a366f619 in main softmmu/main.c:49:5 Fixes: a046433a161 ("Major overhaul of the virtual FAT driver for read/writ= e support") Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Stefano Garzarella --- block/vvfat.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/block/vvfat.c b/block/vvfat.c index 5a4a7915220..2cc21787600 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -3142,7 +3142,7 @@ static int enable_write_target(BlockDriverState *bs, = Error **errp) int size =3D sector2cluster(s, s->sector_count); QDict *options; =20 - s->used_clusters =3D calloc(size, 1); + s->used_clusters =3D g_malloc0(size); =20 array_init(&(s->commits), sizeof(commit_t)); =20 @@ -3233,6 +3233,7 @@ static void vvfat_close(BlockDriverState *bs) array_free(&(s->directory)); array_free(&(s->mapping)); g_free(s->cluster_buffer); + g_free(s->used_clusters); g_free(s->qcow_filename); =20 if (s->qcow) { --=20 2.26.3