From cb19a53db0a5bfa50aa15f3bccf18c8b0e0b330c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Iwanicki?= Date: Wed, 22 Oct 2025 10:02:06 +0200 Subject: [PATCH] flashrom.c: use `finalize_flash_access` in case of failure MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `unlock_flash_wp` which is called in `prepare_flash_access` registers chip restore via `register_chip_restore`. Function failing after this moment would result in memory leak. Fix this issue by calling `finalize_flash_access` even if this function fails. Change-Id: I2e7be3f4f71447a1df532f02d1e45d20c253da5a Signed-off-by: MichaƂ Iwanicki Reviewed-on: https://review.coreboot.org/c/flashrom/+/89684 Tested-by: build bot (Jenkins) Reviewed-by: Anastasia Klimchuk --- flashrom.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/flashrom.c b/flashrom.c index 100fc480a..f6a5be802 100644 --- a/flashrom.c +++ b/flashrom.c @@ -1970,6 +1970,7 @@ int flashrom_flash_erase(struct flashctx *const flashctx) msg_gerr("Error: some of the required checks to prepare flash access failed. " "Earlier messages should give more details.\n" "Erase operation has not started.\n"); + finalize_flash_access(flashctx); return ERROR_FLASHROM_PREPARE_FLASH_ACCESS; } @@ -2081,7 +2082,7 @@ int flashrom_image_write(struct flashctx *const flashctx, void *const buffer, co msg_gerr("Error: some of the required checks to prepare flash access failed. " "Earlier messages should give more details.\n" "Write operation has not started.\n"); - goto _free_ret; + goto _finalize_ret; } /* If given, assume flash chip contains same data as `refcontents`. */