From 226a73bf1b08747d09869d8c95b3a2a0ec5eebed Mon Sep 17 00:00:00 2001 From: Vincent Stehlé Date: Fri, 26 Jun 2026 16:47:58 +0200 Subject: efi_selftest: free handles on teardown() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In the block device selftest, make the handles pointer global and free it also in teardown(), to simplify error handling. We also need to nullify the pointer after freeing it on the normal path, to avoid freeing it a second time during teardown(). Signed-off-by: Vincent Stehlé Reviewed-by: Heinrich Schuchardt --- lib/efi_selftest/efi_selftest_block_device.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/efi_selftest/efi_selftest_block_device.c b/lib/efi_selftest/efi_selftest_block_device.c index 9c4be834eeb..b5f6f9353cd 100644 --- a/lib/efi_selftest/efi_selftest_block_device.c +++ b/lib/efi_selftest/efi_selftest_block_device.c @@ -58,6 +58,9 @@ static const struct compressed_disk_image img = EFI_ST_DISK_IMG; /* Decompressed disk image */ static u8 *image; +/* Handles buffer */ +static efi_handle_t *handles; + /* * Reset service of the block IO protocol. * @@ -276,6 +279,15 @@ static int teardown(void) return EFI_ST_FAILURE; } } + + if (handles) { + r = boottime->free_pool(handles); + if (r != EFI_SUCCESS) { + efi_st_error("Failed to free handles\n"); + return EFI_ST_FAILURE; + } + } + return r; } @@ -303,7 +315,6 @@ static int execute(void) { efi_status_t ret; efi_uintn_t no_handles, i, len; - efi_handle_t *handles; efi_handle_t handle_partition = NULL; struct efi_device_path *dp_partition; struct efi_block_io *block_io_protocol; @@ -372,6 +383,7 @@ static int execute(void) break; } ret = boottime->free_pool(handles); + handles = NULL; /* Avoid double free on teardown(). */ if (ret != EFI_SUCCESS) { efi_st_error("Failed to free pool memory\n"); return EFI_ST_FAILURE; -- cgit v1.3.1