:: commit ef1f9c2f3515adef2e5863c2c9d6c0e1ccd3ea2d

Mintsuki <mintsuki@protonmail.com> — 2026-04-14 13:15

parents: e6172a5d3f

host/limine: Fix empty_lba leak on error during GPT-to-MBR conversion

diff --git a/host/limine.c b/host/limine.c
index 5cebe2ea..ff7bf74f 100644
--- a/host/limine.c
+++ b/host/limine.c
@@ -676,6 +676,7 @@ static int bios_install(int argc, char *argv[]) {
     const uint8_t *bootloader_img = binary_limine_hdd_bin_data;
     size_t   bootloader_file_size = sizeof(binary_limine_hdd_bin_data);
     uint8_t  orig_mbr[70], timestamp[6];
+    void *empty_lba = NULL;
     const char *part_ndx = NULL;
 
 #ifndef __BYTE_ORDER__
@@ -885,7 +886,7 @@ static int bios_install(int argc, char *argv[]) {
         }
 
         // Nuke the GPTs.
-        void *empty_lba = calloc(1, lb_size);
+        empty_lba = calloc(1, lb_size);
         if (empty_lba == NULL) {
             perror_wrap("error: bios_install(): malloc()");
             goto cleanup;
@@ -904,8 +905,6 @@ static int bios_install(int argc, char *argv[]) {
             }
         }
 
-        free(empty_lba);
-
         // We're no longer GPT.
         gpt = 0;
 
@@ -1214,6 +1213,8 @@ cleanup:
     }
 uninstall_mode_cleanup:
     free_uninstall_data();
+    if (empty_lba)
+        free(empty_lba);
     if (cache)
         free(cache);
     if (device != NULL)
tab: 248 wrap: offon