lsefi: fixed memory leaks
PATCH v2 1/1 lsefi: fixed memory leaks
--- grub-core/commands/efi/lsefi.c | 4 ++++ include/grub/efi/efi.h | 27 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+)
grub-core/commands/efi/lsefi.c +4 -0
@@ -127,8 +127,12 @@ grub_cmd_lsefi (grub_command_t cmd __attribute__ ((unused)),grub_printf (" %pG\n" , protocols[j]); } +if (protocols) +grub_efi_free_pool (protocols); } +grub_free (handles); +return 0 ; }
include/grub/efi/efi.h +27 -0
@@ -71,6 +71,7 @@ EXPORT_FUNC(grub_efi_get_memory_map) (grub_efi_uintn_t *memory_map_size, grub_efi_uintn_t *descriptor_size, grub_efi_uint32_t *descriptor_version);void grub_efi_memory_fini (void ); +grub_efi_loaded_image_t *EXPORT_FUNC (grub_efi_get_loaded_image ) (grub_efi_handle_t image_handle);void EXPORT_FUNC (grub_efi_print_device_path ) (grub_efi_device_path_t *dp);char *EXPORT_FUNC (grub_efi_get_filename ) (grub_efi_device_path_t *dp);
@@ -193,4 +194,30 @@ struct grub_net_card;grub_efi_handle_t grub_efinet_get_device_handle (struct grub_net_card *card); +static inline grub_efi_status_t +__attribute__((__unused__)) +grub_efi_allocate_pool (grub_efi_memory_type_t pool_type, +grub_efi_uintn_t buffer_size, +void **buffer) +{ +grub_efi_boot_services_t *b; +grub_efi_status_t status; + + b = grub_efi_system_table->boot_services; + status = b->allocate_pool (pool_type, buffer_size, buffer); +return status; +} + +static inline grub_efi_status_t +__attribute__((__unused__)) +grub_efi_free_pool (void *buffer) +{ +grub_efi_boot_services_t *b; +grub_efi_status_t status; + + b = grub_efi_system_table->boot_services; + status = b->free_pool (buffer); +return status; +} +#endif /* ! GRUB_EFI_EFI_HEADER */
Signature · 7 lines
2.51.0 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
Hello,
I'm very sorry for having submitted a broken patch earlier, I didn't notice I had not committed the efi.h file which is now defining the required grub_efi_free_pool() function.
Renaud.
Le 9/2/25 à 1:55 PM, Renaud Métrich a écrit :
Quoted 56 lines
Signed-off-by Renaud Métrich <[email protected]>--- grub-core/commands/efi/lsefi.c | 4 ++++ include/grub/efi/efi.h | 27 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+)grub-core/commands/efi/lsefi.c +4
-0@@ -127,8 +127,12 @@ grub_cmd_lsefi (grub_command_t cmd __attribute__ ((unused)),grub_printf (" %pG\n" , protocols[j]); } +if (protocols) +grub_efi_free_pool (protocols); } +grub_free (handles); +return 0 ; }include/grub/efi/efi.h +18
-0@@ -71,6 +71,7 @@ EXPORT_FUNC(grub_efi_get_memory_map) (grub_efi_uintn_t *memory_map_size, grub_efi_uintn_t *descriptor_size, grub_efi_uint32_t *descriptor_version);void grub_efi_memory_fini (void ); +grub_efi_loaded_image_t *EXPORT_FUNC (grub_efi_get_loaded_image ) (grub_efi_handle_t image_handle);void EXPORT_FUNC (grub_efi_print_device_path ) (grub_efi_device_path_t *dp);char *EXPORT_FUNC (grub_efi_get_filename ) (grub_efi_device_path_t *dp);@@ -193,4 +194,30 @@ struct grub_net_card;grub_efi_handle_t grub_efinet_get_device_handle (struct grub_net_card *card); +static inline grub_efi_status_t +__attribute__((__unused__)) +grub_efi_allocate_pool (grub_efi_memory_type_t pool_type, +grub_efi_uintn_t buffer_size, +void **buffer) +{ +grub_efi_boot_services_t *b; +grub_efi_status_t status; + + b = grub_efi_system_table->boot_services; + status = b->allocate_pool (pool_type, buffer_size, buffer); +return status; +} + +static inline grub_efi_status_t +__attribute__((__unused__)) +grub_efi_free_pool (void *buffer)
include/grub/efi/efi.h struct grub_net_card; · line 223
Quoted 10 lines
include/grub/efi/efi.h +9
-0+{ +grub_efi_boot_services_t *b; +grub_efi_status_t status; + + b = grub_efi_system_table->boot_services; + status = b->free_pool (buffer); +return status; +} +#endif /* ! GRUB_EFI_EFI_HEADER */
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Quoted 28 lines · Renaud Métrich via Grub-devel
Signed-off-by Renaud Métrich <[email protected]>--- grub-core/commands/efi/lsefi.c | 4 ++++ include/grub/efi/efi.h | 27 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+)grub-core/commands/efi/lsefi.c +4
-0@@ -127,8 +127,12 @@ grub_cmd_lsefi (grub_command_t cmd __attribute__ ((unused)),grub_printf (" %pG\n" , protocols[j]); } +if (protocols) +grub_efi_free_pool (protocols); } +grub_free (handles); +return 0 ; }include/grub/efi/efi.h +0
-0
include/grub/efi/efi.h EXPORT_FUNC(grub_efi_get_memory_map) (grub_efi_uintn_t *memory_map_size, · line 74
Quoted 4 lines
include/grub/efi/efi.h +1
-0@@ -71,6 +71,7 @@ EXPORT_FUNC(grub_efi_get_memory_map) (grub_efi_uintn_t *memory_map_size, grub_efi_uintn_t *descriptor_size, grub_efi_uint32_t *descriptor_version);void grub_efi_memory_fini (void ); +
Please drop this noise...
include/grub/efi/efi.h struct grub_net_card; · line 198
Quoted 9 lines
include/grub/efi/efi.h +2
-0grub_efi_loaded_image_t *EXPORT_FUNC (grub_efi_get_loaded_image ) (grub_efi_handle_t image_handle);void EXPORT_FUNC (grub_efi_print_device_path ) (grub_efi_device_path_t *dp);char *EXPORT_FUNC (grub_efi_get_filename ) (grub_efi_device_path_t *dp);@@ -193,4 +194,30 @@ struct grub_net_card;grub_efi_handle_t grub_efinet_get_device_handle (struct grub_net_card *card); +static inline grub_efi_status_t +__attribute__((__unused__))
Please drop this attribute. And if you introduce this function please do this in separate patch and add its call in grub-core/kern/efi/mm.c.
include/grub/efi/efi.h struct grub_net_card; · line 207
Quoted 9 lines
include/grub/efi/efi.h +9
-0+grub_efi_allocate_pool (grub_efi_memory_type_t pool_type, + grub_efi_uintn_t buffer_size, + void **buffer) +{ + grub_efi_boot_services_t *b; +grub_efi_status_t status; + + b = grub_efi_system_table->boot_services; + status = b->allocate_pool (pool_type, buffer_size, buffer);
Missing space before "(".
include/grub/efi/efi.h struct grub_net_card; · line 212
Quoted 5 lines
include/grub/efi/efi.h +5
-0+return status; +} + +static inline grub_efi_status_t +__attribute__((__unused__))
This attribute is not needed.
include/grub/efi/efi.h struct grub_net_card; · line 219
Quoted 7 lines
include/grub/efi/efi.h +7
-0+grub_efi_free_pool (void *buffer) +{ +grub_efi_boot_services_t *b; +grub_efi_status_t status; + + b = grub_efi_system_table->boot_services; + status = b->free_pool (buffer);
Missing space before "(".
include/grub/efi/efi.h struct grub_net_card; · line 223
Quoted 4 lines
include/grub/efi/efi.h +3
-0+ return status; +} +#endif /* ! GRUB_EFI_EFI_HEADER */
FYI, I am planning code freeze on 3rd of October 2025. If you want me to take your patches into the upcoming release I suggest to speed up a turn over...
Daniel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Hi Daniel,
This code requires porting of functions available in RHEL fork only: grub_efi_free_pool() and grub_efi_allocate_pool()
Discussing with Marta Lewando from Red Hat, she told me this will be a separate patch, hence we shall defer until that patch is merged with Upstream.
Renaud.
Le 9/4/25 à 3:59 PM, Daniel Kiper a écrit :
Quoted 82 lines · Renaud Métrich via Grub-devel
Quoted 28 lines
Signed-off-by Renaud Métrich <[email protected]>--- grub-core/commands/efi/lsefi.c | 4 ++++ include/grub/efi/efi.h | 27 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+)grub-core/commands/efi/lsefi.c +4
-0@@ -127,8 +127,12 @@ grub_cmd_lsefi (grub_command_t cmd __attribute__ ((unused)),grub_printf (" %pG\n" , protocols[j]); } +if (protocols) +grub_efi_free_pool (protocols); } +grub_free (handles); +return 0 ; }include/grub/efi/efi.h +0
-0include/grub/efi/efi.h EXPORT_FUNC(grub_efi_get_memory_map) (grub_efi_uintn_t *memory_map_size, · line 74
Quoted 4 lines
include/grub/efi/efi.h +1
-0@@ -71,6 +71,7 @@ EXPORT_FUNC(grub_efi_get_memory_map) (grub_efi_uintn_t *memory_map_size, grub_efi_uintn_t *descriptor_size, grub_efi_uint32_t *descriptor_version);void grub_efi_memory_fini (void ); +Please drop this noise...
include/grub/efi/efi.h struct grub_net_card; · line 198
Quoted 9 lines
include/grub/efi/efi.h +2
-0grub_efi_loaded_image_t *EXPORT_FUNC (grub_efi_get_loaded_image ) (grub_efi_handle_t image_handle);void EXPORT_FUNC (grub_efi_print_device_path ) (grub_efi_device_path_t *dp);char *EXPORT_FUNC (grub_efi_get_filename ) (grub_efi_device_path_t *dp);@@ -193,4 +194,30 @@ struct grub_net_card;grub_efi_handle_t grub_efinet_get_device_handle (struct grub_net_card *card); +static inline grub_efi_status_t +__attribute__((__unused__))Please drop this attribute. And if you introduce this function please do this in separate patch and add its call in
grub-core/kern/efi/mm.c.include/grub/efi/efi.h struct grub_net_card; · line 207
Quoted 9 lines
include/grub/efi/efi.h +9
-0+grub_efi_allocate_pool (grub_efi_memory_type_t pool_type, + grub_efi_uintn_t buffer_size, + void **buffer) +{ + grub_efi_boot_services_t *b; +grub_efi_status_t status; + + b = grub_efi_system_table->boot_services; + status = b->allocate_pool (pool_type, buffer_size, buffer);Missing space before "(".
include/grub/efi/efi.h struct grub_net_card; · line 212
Quoted 5 lines
include/grub/efi/efi.h +5
-0+return status; +} + +static inline grub_efi_status_t +__attribute__((__unused__))This attribute is not needed.
include/grub/efi/efi.h struct grub_net_card; · line 219
Quoted 7 lines
include/grub/efi/efi.h +7
-0+grub_efi_free_pool (void *buffer) +{ +grub_efi_boot_services_t *b; +grub_efi_status_t status; + + b = grub_efi_system_table->boot_services; + status = b->free_pool (buffer);Missing space before "(".
include/grub/efi/efi.h struct grub_net_card; · line 223
Quoted 4 lines
include/grub/efi/efi.h +3
-0+ return status; +} +#endif /* ! GRUB_EFI_EFI_HEADER */ FYI, I am planning code freeze on 3rd of October 2025. If you want me to take your patches into the upcoming release I suggest to speed up a turn over...
Quoted 2 lines
Daniel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel