Skip to content

Commit 04fa282

Browse files
committed
Better error handling and freeing of leaked descriptors in vgabios.bin code
Also change the vgabios.bin file path from /EFI/BOOT/ to /EFI/CSMWrap/.
1 parent 4902aad commit 04fa282

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/csmwrap.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,16 +126,19 @@ EFI_STATUS efi_main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
126126

127127
EFI_FILE_PROTOCOL *vgabios_file_handle = NULL;
128128
if (sfs_dir != NULL) {
129-
if (sfs_dir->Open(sfs_dir, &vgabios_file_handle, L"\\EFI\\BOOT\\vgabios.bin", EFI_FILE_MODE_READ, 0) == EFI_SUCCESS) {
130-
printf("Found 'vgabios.bin' file. Using it as our VBIOS!\n");
129+
if (sfs_dir->Open(sfs_dir, &vgabios_file_handle, L"\\EFI\\CSMWrap\\vgabios.bin", EFI_FILE_MODE_READ, 0) == EFI_SUCCESS) {
131130
UINTN max_size = 256 * 1024;
132-
if (gBS->AllocatePool(EfiLoaderData, max_size, &vbios_loc) == EFI_SUCCESS
133-
&& vgabios_file_handle->Read(vgabios_file_handle, &max_size, vbios_loc) == EFI_SUCCESS) {
131+
if (gBS->AllocatePool(EfiLoaderData, max_size, &vbios_loc) != EFI_SUCCESS) {
132+
vbios_loc = NULL;
133+
}
134+
if (vbios_loc != NULL && vgabios_file_handle->Read(vgabios_file_handle, &max_size, vbios_loc) == EFI_SUCCESS) {
135+
printf("Found and loaded '\\EFI\\CSMWrap\\vgabios.bin' file. Using it as our VBIOS!\n");
134136
vbios_size = max_size;
135137
} else {
138+
gBS->FreePool(vbios_loc);
136139
vbios_loc = NULL;
137-
vbios_size = 0;
138140
}
141+
vgabios_file_handle->Close(vgabios_file_handle);
139142
}
140143
sfs_dir->Close(sfs_dir);
141144
}

0 commit comments

Comments
 (0)