From nobody Mon Feb 9 23:39:27 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=1619799940; cv=none; d=zohomail.com; s=zohoarc; b=dNS2HXTsndqkwlY8oyfRUdF+LRnbn9mYAL3T1PlxYauAaphDMhHr+spQFBaeNKuZLUwP52g1rBfllN+SV47aDhfVec1QFQ8oMefkZEVCMQWCaWDoYtFP50PDJojmwUMwUxTTiUfsncxiWGjqyt2NqV3401DTIeqVWdfVZz7zqc8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619799940; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=gB7HrfP9JiCLO2S9Qgx/afIOpRLRteER0wJyUW0tVjw=; b=ZVAH+vyUMhYYUXRGjFGWjuxNcv7WIlUHftAXweIUu3vC8UskO2wTw2x9DFbjf3mgIDQ2kS0tCvp4SfzzqxsO4E+3wrSh+XR9SwzEhqpg+81slLNV0q/q1CMikXf83/UF8zwhr/HHBc9TcBrK9jsug6Z2iQnCGPYeRCRzRm3+azE= 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 1619799940803427.52650012921697; Fri, 30 Apr 2021 09:25:40 -0700 (PDT) Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-216-4GuRvuJ2NICwNbpLeRjavQ-1; Fri, 30 Apr 2021 12:25:37 -0400 Received: by mail-wr1-f70.google.com with SMTP id q18-20020adfc5120000b029010c2bdd72adso7819514wrf.16 for ; Fri, 30 Apr 2021 09:25:37 -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 s6sm15817797wms.0.2021.04.30.09.25.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Apr 2021 09:25:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619799939; 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=gB7HrfP9JiCLO2S9Qgx/afIOpRLRteER0wJyUW0tVjw=; b=KMGDc2FHF826FR+awjmr9/U2+xTKhvWQcu+wjXcy4ZvLuXkCl8UJDItOL6b+OrPmXe9Exp 7UWsZCeqHzipKvUlLib4Hhm0DZtEfBVIENK+lqE2zV6m2DaFddKlbG+9BrInfKA/KUyE05 jZuojWojEoieFaYTnkoi+NqFt8/osSg= X-MC-Unique: 4GuRvuJ2NICwNbpLeRjavQ-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=gB7HrfP9JiCLO2S9Qgx/afIOpRLRteER0wJyUW0tVjw=; b=gxqwc+XcIlWZ4omNPbaLcfEK/gHSzqaZIrdEo/OjBBPtNMqEyH2Qn85q4JxMozfEJU CpG2wfcmFx8j35jIJth/XqnegDPFB9w9XdYDhx1mxOCYE/DDQjw9A594NSAOl5qwGEhi 1ZJeLJsd3RkPPxP2L75A9Io0QcwX4cxwtmm8u4H9A9cK4OXpfq4aApMDas1V48t7xwhA fHKtF2Hp8z3V87VwzveuYL+0/wiwPIxaMrus+IA38Qzkbzxl0wmW0MY64uJV83qtC7Xj UhidNmJbN1Gi5nD274d6lnj5ehFGbKeUuuiCpVWiiFbMYfuSCNfnxokz/hf7OrWkPiMp LdrQ== X-Gm-Message-State: AOAM5333Gm1Gd4Ujb/G8nVivOsiNFXdiTUKtQs0wN4ktlrGImhbBgmkD KEBnderQhWJtG8mBvRVaQ2wlbf3c2SFyFemTGQKh8guaHlpImQD125bdms+Tzj++8asrFQia7hU pRhFFR8nCWAHDxw== X-Received: by 2002:a05:600c:3643:: with SMTP id y3mr17079467wmq.159.1619799936713; Fri, 30 Apr 2021 09:25:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw+KyZNJykbyKouIX1D2w8MWC4uDz/zRYICCgIwlYwdp01y8vAH3k9LVLOxIZCZp+WyKxKihg== X-Received: by 2002:a05:600c:3643:: with SMTP id y3mr17079453wmq.159.1619799936587; Fri, 30 Apr 2021 09:25:36 -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 3/4] block/vvfat: Fix leak of mapping_t::path Date: Fri, 30 Apr 2021 18:25:18 +0200 Message-Id: <20210430162519.271607-4-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) read_directory() keeps pointers to alloc'ed data in path ...: 743 static int read_directory(BDRVVVFATState* s, int mapping_index) 744 { ... 792 buffer =3D g_malloc(length); ... 828 /* create mapping for this file */ 829 if(!is_dot && !is_dotdot && (S_ISDIR(st.st_mode) || st.st_size= )) { 830 s->current_mapping =3D array_get_next(&(s->mapping)); ... 847 s->current_mapping->path=3Dbuffer; ... but these pointers are never free'd. Free them in vvfat_close(), to fix (QEMU built with --enable-sanitizers): Direct leak of 148 byte(s) in 6 object(s) allocated from: #0 0x55d7a363773f in malloc (qemu-system-x86_64+0x1dab73f) #1 0x7f55c6447958 in g_malloc (/lib64/libglib-2.0.so.0+0x58958) #2 0x55d7a5e17679 in init_directories block/vvfat.c:962:16 #3 0x55d7a5e1251e in vvfat_open block/vvfat.c:1255:9 #4 0x55d7a5a5363f in bdrv_open_driver block.c:1526:15 #5 0x55d7a5a9d369 in bdrv_open_common block.c:1802:11 #6 0x55d7a5a609f1 in bdrv_open_inherit block.c:3444:11 #7 0x55d7a5a65411 in bdrv_open_child_bs block.c:3079:10 #8 0x55d7a5a60079 in bdrv_open_inherit block.c:3391:19 #9 0x55d7a5a65da3 in bdrv_open block.c:3537:12 #10 0x55d7a5b33f6a in blk_new_open block/block-backend.c:421:10 #11 0x55d7a5a0a33e in blockdev_init blockdev.c:610:15 #12 0x55d7a5a088e7 in drive_new blockdev.c:994:11 #13 0x55d7a51b10c4 in drive_init_func softmmu/vl.c:636:12 #14 0x55d7a620e148 in qemu_opts_foreach util/qemu-option.c:1167:14 #15 0x55d7a51b0e20 in configure_blockdev softmmu/vl.c:695:9 #16 0x55d7a51a70b5 in qemu_create_early_backends softmmu/vl.c:1895:5 #17 0x55d7a519bf87 in qemu_init softmmu/vl.c:3551:5 #18 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: Max Reitz --- block/vvfat.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/block/vvfat.c b/block/vvfat.c index 2cc21787600..c193a816646 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -3228,6 +3228,11 @@ static void vvfat_close(BlockDriverState *bs) { BDRVVVFATState *s =3D bs->opaque; =20 + for (unsigned j =3D 0; j < s->mapping.next; j++) { + mapping_t *mapping =3D array_get(&(s->mapping), j); + + g_free(mapping->path); + } vvfat_close_current_file(s); array_free(&(s->fat)); array_free(&(s->directory)); --=20 2.26.3