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

This commit is contained in:
Mintsuki
2026-04-14 15:15:31 +02:00
parent a9b148ed74
commit 0fb6bb6c7c

View File

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