mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-12-18 21:48:36 -07:00
loader: extract rom_free() function
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 = 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 <stefanha@redhat.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Message-id: 20180814162739.11814-4-stefanha@redhat.com
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
parent
191776b96a
commit
e7f5993354
1 changed files with 12 additions and 9 deletions
|
|
@ -847,6 +847,17 @@ struct Rom {
|
||||||
static FWCfgState *fw_cfg;
|
static FWCfgState *fw_cfg;
|
||||||
static QTAILQ_HEAD(, Rom) roms = QTAILQ_HEAD_INITIALIZER(roms);
|
static QTAILQ_HEAD(, Rom) roms = QTAILQ_HEAD_INITIALIZER(roms);
|
||||||
|
|
||||||
|
/* 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)
|
static inline bool rom_order_compare(Rom *rom, Rom *item)
|
||||||
{
|
{
|
||||||
return ((uintptr_t)(void *)rom->as > (uintptr_t)(void *)item->as) ||
|
return ((uintptr_t)(void *)rom->as > (uintptr_t)(void *)item->as) ||
|
||||||
|
|
@ -995,15 +1006,7 @@ err:
|
||||||
if (fd != -1)
|
if (fd != -1)
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
g_free(rom->data);
|
rom_free(rom);
|
||||||
g_free(rom->path);
|
|
||||||
g_free(rom->name);
|
|
||||||
if (fw_dir) {
|
|
||||||
g_free(rom->fw_dir);
|
|
||||||
g_free(rom->fw_file);
|
|
||||||
}
|
|
||||||
g_free(rom);
|
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue