diff options
| author | Ada Christine <adachristine18@gmail.com> | 2024-02-15 22:51:17 +0000 |
|---|---|---|
| committer | Ada Christine <adachristine18@gmail.com> | 2024-02-15 22:51:17 +0000 |
| commit | 0b62b5cd53c5ae58fe724db7d84d351466a161c9 (patch) | |
| tree | 205b35cfe363605d531fe282ae7b2d1c6a9e6fa5 | |
| parent | 96ff1a24a7474b91c44a3dcd6f3abf3ec0542191 (diff) | |
free resources
| -rw-r--r-- | kjarna/efi/file.c | 29 | ||||
| -rw-r--r-- | kjarna/efi/kjarna_efi.h | 1 | ||||
| -rw-r--r-- | kjarna/efi/protocol.c | 9 | ||||
| -rw-r--r-- | kjarna/efi/runtime.c | 1 |
4 files changed, 19 insertions, 21 deletions
diff --git a/kjarna/efi/file.c b/kjarna/efi/file.c index 6888390..12364e6 100644 --- a/kjarna/efi/file.c +++ b/kjarna/efi/file.c @@ -66,32 +66,17 @@ static void free_fd(int fd) int efi_open(const char *path, int flags, int mode) { - EFI_GUID lip_guid = EFI_LOADED_IMAGE_PROTOCOL_GUID; - EFI_LOADED_IMAGE_PROTOCOL *lip = nullptr; - - efi_errno = gBS->OpenProtocol( - efi_context->handle, - &lip_guid, - (void **)&lip, - efi_context->handle, - nullptr, - EFI_OPEN_PROTOCOL_GET_PROTOCOL); + static EFI_GUID lip_guid = EFI_LOADED_IMAGE_PROTOCOL_GUID; + static EFI_GUID sfsp_guid = EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID; + + EFI_LOADED_IMAGE_PROTOCOL *lip = efi_get_protocol(efi_context->handle, &lip_guid); if (lip == nullptr) { return -1; } - EFI_GUID sfsp_guid = EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID; - EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *sfsp = nullptr; - - efi_errno = gBS->OpenProtocol( - lip->DeviceHandle, - &sfsp_guid, - (void **)&sfsp, - efi_context->handle, - nullptr, - EFI_OPEN_PROTOCOL_GET_PROTOCOL); + EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *sfsp = efi_get_protocol(lip->DeviceHandle, &sfsp_guid); if (sfsp == nullptr) { @@ -117,7 +102,7 @@ int efi_open(const char *path, int flags, int mode) size_t path_len = strlen(path) + 1; CHAR16 *wcpath = efi_calloc_pool(path_len, sizeof(*wcpath)); - if(mbstowcs(wcpath, path, path_len) == (size_t)-1) + if (mbstowcs(wcpath, path, path_len) == (size_t)-1) { efi_errno = EFI_INVALID_PARAMETER; } @@ -131,6 +116,8 @@ int efi_open(const char *path, int flags, int mode) 0); } + efi_close_protocol(lip->DeviceHandle, &lip_guid); + efi_close_protocol(efi_context->handle, &sfsp_guid); efi_free_pool(wcpath); (void)flags; diff --git a/kjarna/efi/kjarna_efi.h b/kjarna/efi/kjarna_efi.h index 48b0034..ea9d3f1 100644 --- a/kjarna/efi/kjarna_efi.h +++ b/kjarna/efi/kjarna_efi.h @@ -20,6 +20,7 @@ extern EFI_STATUS efi_errno; #define gBS efi_context->system_table->BootServices void *efi_get_protocol(EFI_HANDLE handle, EFI_GUID *guid); +void efi_close_protocol(EFI_HANDLE handle, EFI_GUID *guid); int SYSV_ABI efi_open(const char *path, int flags, int mode); int SYSV_ABI efi_close(int fd); diff --git a/kjarna/efi/protocol.c b/kjarna/efi/protocol.c index e4be9cd..6bf8123 100644 --- a/kjarna/efi/protocol.c +++ b/kjarna/efi/protocol.c @@ -22,3 +22,12 @@ void *efi_get_protocol(EFI_HANDLE handle, EFI_GUID *guid) return protocol; } +void efi_close_protocol(EFI_HANDLE handle, EFI_GUID *guid) +{ + efi_errno = gBS->CloseProtocol( + handle, + guid, + efi_context->handle, + nullptr); +} + diff --git a/kjarna/efi/runtime.c b/kjarna/efi/runtime.c index 5f2e7e1..d9be2df 100644 --- a/kjarna/efi/runtime.c +++ b/kjarna/efi/runtime.c @@ -124,6 +124,7 @@ static struct runtime_buffer load_runtime(void) buffer.base = nullptr; } + efi_close(runtime_fd); efi_free_pool(phdrs); return buffer; |
