]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
efi_loader: Do not leak memory when unlinking a mapping
authorStefan Brüns <stefan.bruens@rwth-aachen.de>
Sat, 1 Oct 2016 21:32:29 +0000 (23:32 +0200)
committerAlexander Graf <agraf@suse.de>
Tue, 18 Oct 2016 07:08:08 +0000 (09:08 +0200)
As soon as a mapping is unlinked from the list, there are no further
references to it, so it should be freed. If it not unlinked,
update the start address and length.

Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
Reviewed-by: Alexander Graf <agraf@suse.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
lib/efi_loader/efi_memory.c

index 742bc9084ffc32678649188be807ed39c662b8ed..95aa590c8af7a4d53697091b4292e2bac59a1f9e 100644 (file)
@@ -116,10 +116,13 @@ static int efi_mem_carve_out(struct efi_mem_list *map,
                if (map_end == carve_end) {
                        /* Full overlap, just remove map */
                        list_del(&map->link);
+                       free(map);
+               } else {
+                       map->desc.physical_start = carve_end;
+                       map->desc.num_pages = (map_end - carve_end)
+                                             >> EFI_PAGE_SHIFT;
                }
 
-               map_desc->physical_start = carve_end;
-               map_desc->num_pages = (map_end - carve_end) >> EFI_PAGE_SHIFT;
                return (carve_end - carve_start) >> EFI_PAGE_SHIFT;
        }