[PATCH v3 1/2] efi_selftest: free handles on teardown()

Heinrich Schuchardt xypron.glpk at gmx.de
Sun Jul 12 07:50:43 CEST 2026


On 7/12/26 07:26, Heinrich Schuchardt wrote:
> On 6/26/26 16:47, Vincent Stehlé wrote:
>> 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 at arm.com>
>> ---
>>   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(). */
> 
> Thank you for fixing the memory leak.
> 
> handles is a static variable. Why do you explicitly set it to NULL?
> 
> Best regards
> 
> Heinrich

Sorry I misread the patch.

Reviewed-by: Heinrich Schuchardt <xypron.glpk at gmx.de>

> 
>>       if (ret != EFI_SUCCESS) {
>>           efi_st_error("Failed to free pool memory\n");
>>           return EFI_ST_FAILURE;
>>
> 



More information about the U-Boot mailing list