From 2ef2efa0fa6a920fe3dd8f067a6632798b214bcd Mon Sep 17 00:00:00 2001 From: Angel Pons Date: Tue, 25 May 2021 12:56:18 +0200 Subject: dummyflasher.c: Move `flashchip_contents` allocation Place `flashchip_contents` allocation next to the code that initialises the newly-allocated buffer. This also avoids leaking it if the handling of `spi_status` fails. Change-Id: Ie907ac88dfe4ca018c97d9ce6ce042b4ffacf36a Signed-off-by: Angel Pons Reviewed-on: https://review.coreboot.org/c/flashrom/+/54908 Tested-by: build bot (Jenkins) Reviewed-by: Edward O'Callaghan Reviewed-by: Anastasia Klimchuk --- dummyflasher.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/dummyflasher.c b/dummyflasher.c index 717f8d11..5defec01 100644 --- a/dummyflasher.c +++ b/dummyflasher.c @@ -957,12 +957,6 @@ int dummy_init(void) } free(tmp); - data->flashchip_contents = malloc(data->emu_chip_size); - if (!data->flashchip_contents) { - msg_perr("Out of memory!\n"); - return 1; - } - #ifdef EMULATE_SPI_CHIP status = extract_programmer_param("spi_status"); if (status) { @@ -979,6 +973,12 @@ int dummy_init(void) } #endif + data->flashchip_contents = malloc(data->emu_chip_size); + if (!data->flashchip_contents) { + msg_perr("Out of memory!\n"); + return 1; + } + msg_pdbg("Filling fake flash chip with 0x%02x, size %i\n", data->erase_to_zero ? 0x00 : 0xff, data->emu_chip_size); memset(data->flashchip_contents, data->erase_to_zero ? 0x00 : 0xff, data->emu_chip_size); -- cgit v1.2.3