From nobody Mon Feb 9 23:38:46 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1533307825076825.7273045225803; Fri, 3 Aug 2018 07:50:25 -0700 (PDT) Received: from localhost ([::1]:51732 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1flbPH-0004Oy-0n for importer@patchew.org; Fri, 03 Aug 2018 10:50:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49849) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1flbMh-0002iY-Cq for qemu-devel@nongnu.org; Fri, 03 Aug 2018 10:47:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1flbMe-0007fX-Oz for qemu-devel@nongnu.org; Fri, 03 Aug 2018 10:47:37 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:32966 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1flbMc-0007da-N7; Fri, 03 Aug 2018 10:47:34 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 28BA6818A6B9; Fri, 3 Aug 2018 14:47:34 +0000 (UTC) Received: from localhost (ovpn-117-231.ams2.redhat.com [10.36.117.231]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9FC0A215670D; Fri, 3 Aug 2018 14:47:33 +0000 (UTC) From: Stefan Hajnoczi To: Date: Fri, 3 Aug 2018 15:47:18 +0100 Message-Id: <20180803144721.17036-4-stefanha@redhat.com> In-Reply-To: <20180803144721.17036-1-stefanha@redhat.com> References: <20180803144721.17036-1-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 03 Aug 2018 14:47:34 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 03 Aug 2018 14:47:34 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'stefanha@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v4 3/6] loader: extract rom_free() function X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , jim@groklearning.com, mail@steffen-goertz.de, Su Hang , ilg@livius.net, Alistair Francis , Subbaraya Sundeep , Steffen Gortz , qemu-arm@nongnu.org, Joel Stanley , Stefan Hajnoczi , jusual@mail.ru Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The next patch will need to free a rom. There is already code to do this in rom_add_file(). Note that rom_add_file() uses: rom =3D g_malloc0(sizeof(*rom)); ... if (rom->fw_dir) { g_free(rom->fw_dir); g_free(rom->fw_file); } The conditional is unnecessary since g_free(NULL) is a no-op. Signed-off-by: Stefan Hajnoczi Reviewed-by: Alistair Francis Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/core/loader.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/hw/core/loader.c b/hw/core/loader.c index bbb6e65bb5..0c72e7c05a 100644 --- a/hw/core/loader.c +++ b/hw/core/loader.c @@ -847,6 +847,17 @@ struct Rom { static FWCfgState *fw_cfg; static QTAILQ_HEAD(, Rom) roms =3D QTAILQ_HEAD_INITIALIZER(roms); =20 +/* rom->data must be heap-allocated (do not use with rom_add_elf_program()= ) */ +static void rom_free(Rom *rom) +{ + g_free(rom->data); + g_free(rom->path); + g_free(rom->name); + g_free(rom->fw_dir); + g_free(rom->fw_file); + g_free(rom); +} + static inline bool rom_order_compare(Rom *rom, Rom *item) { return ((uintptr_t)(void *)rom->as > (uintptr_t)(void *)item->as) || @@ -995,15 +1006,7 @@ err: if (fd !=3D -1) close(fd); =20 - g_free(rom->data); - g_free(rom->path); - g_free(rom->name); - if (fw_dir) { - g_free(rom->fw_dir); - g_free(rom->fw_file); - } - g_free(rom); - + rom_free(rom); return -1; } =20 --=20 2.17.1