]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
efi_selftest: free handles on teardown()
authorVincent Stehlé <vincent.stehle@arm.com>
Fri, 26 Jun 2026 14:47:58 +0000 (16:47 +0200)
committerHeinrich Schuchardt <heinrich.schuchardt@canonical.com>
Wed, 15 Jul 2026 22:40:42 +0000 (00:40 +0200)
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é <vincent.stehle@arm.com>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
lib/efi_selftest/efi_selftest_block_device.c

index 9c4be834eebb220cb465aa17a6e7c0c49248ffa0..b5f6f9353cdc589070fad7348b076ff0fe856bd7 100644 (file)
@@ -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;