fix(eficore): unregister media loader on drop to prevent more opportunities for leaks (#50)

This commit is contained in:
alex authored and GitHub committed 2025-12-20 22:01:04 -08:00
1 parent 2da457ee7c
commit 17e729d068
3 files changed
+19 -17

No files matched your search

+3 -8
View File
@@ -10,7 +10,6 @@ use eficore::loader::source::ImageSource;
use eficore::loader::{ImageLoadRequest, ImageLoader};
use eficore::media_loader::MediaLoaderHandle;
use eficore::media_loader::constants::linux::LINUX_EFI_INITRD_MEDIA_GUID;
use log::error;
use uefi::CString16;
use uefi::proto::loaded_image::LoadedImage;
@@ -99,19 +98,15 @@ pub fn chainload(context: Rc<SproutContext>, configuration: &ChainloadConfigurat
// after the optional initrd has been unregistered.
let result = uefi::boot::start_image(*image.handle());
// Unregister the initrd if it was registered.
if let Some(initrd_handle) = initrd_handle
&& let Err(error) = initrd_handle.unregister()
{
error!("unable to unregister linux initrd: {}", error);
}
// Assert there was no error starting the image.
result.context("unable to start image")?;
// Explicitly drop the options to clarify the lifetime.
drop(options);
// Explicitly drop the initrd handle to clarify when it should be unregistered.
drop(initrd_handle);
// Return control to sprout.
Ok(())
}