From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42330) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fpdOY-0006Fl-LN for qemu-devel@nongnu.org; Tue, 14 Aug 2018 13:46:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fpdOJ-0002TF-Gj for qemu-devel@nongnu.org; Tue, 14 Aug 2018 13:46:14 -0400 From: Stefan Hajnoczi Date: Tue, 14 Aug 2018 17:27:36 +0100 Message-Id: <20180814162739.11814-4-stefanha@redhat.com> In-Reply-To: <20180814162739.11814-1-stefanha@redhat.com> References: <20180814162739.11814-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH v6 3/6] loader: extract rom_free() function List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Julia Suvorova , Peter Maydell , joel@jms.id.au, qemu-arm@nongnu.org, Subbaraya Sundeep , jim@groklearning.com, Alistair Francis , Steffen Gortz , mail@steffen-goertz.de, Su Hang , ilg@livius.net, Stefan Hajnoczi 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