graphics: Fix memory leak when resizing the display

This commit is contained in:
bjorn3
2025-07-06 16:22:41 +02:00
parent ded7a6ed86
commit 93e95f6fe8
3 changed files with 39 additions and 1 deletions
+17
View File
@@ -496,6 +496,23 @@ impl<T: GraphicsAdapter> SchemeSync for GraphicsScheme<T> {
Ok(size_of::<ipc::DumbFramebufferMapOffset>())
}
ipc::DESTROY_DUMB_FRAMEBUFFER => {
if payload.len() < size_of::<ipc::DestroyDumbFramebuffer>() {
return Err(Error::new(EINVAL));
}
let payload = unsafe {
transmute::<
&mut [u8; size_of::<ipc::DestroyDumbFramebuffer>()],
&mut ipc::DestroyDumbFramebuffer,
>(payload.as_mut_array().unwrap())
};
if fbs.remove(&{ payload.fb_id }).is_none() {
return Err(Error::new(ENOENT));
}
Ok(size_of::<ipc::DestroyDumbFramebuffer>())
}
ipc::UPDATE_PLANE => {
if payload.len() < size_of::<ipc::UpdatePlane>() {
return Err(Error::new(EINVAL));
+2
View File
@@ -95,6 +95,8 @@ impl FbbootlogScheme {
},
);
let _ = map.display_handle.destroy_dumb_framebuffer(map.fb);
map.fb = fb;
map.inner = new_map;
+20 -1
View File
@@ -124,6 +124,19 @@ impl V2GraphicsHandle {
Ok(unsafe { DisplayMap::new(offscreen, width as usize, height as usize) })
}
pub fn destroy_dumb_framebuffer(&self, id: usize) -> io::Result<usize> {
let mut cmd = ipc::DestroyDumbFramebuffer { fb_id: id };
unsafe {
sys_call(
&self.file,
&mut cmd,
0,
&[ipc::DESTROY_DUMB_FRAMEBUFFER, 0, 0],
)?;
}
Ok(cmd.fb_id)
}
pub fn update_plane(&self, display_id: usize, fb_id: usize, damage: Damage) -> io::Result<()> {
let mut cmd = ipc::UpdatePlane {
display_id,
@@ -172,7 +185,13 @@ pub mod ipc {
pub offset: usize,
}
pub const UPDATE_PLANE: u64 = 5;
pub const DESTROY_DUMB_FRAMEBUFFER: u64 = 5;
#[repr(C, packed)]
pub struct DestroyDumbFramebuffer {
pub fb_id: usize,
}
pub const UPDATE_PLANE: u64 = 6;
#[repr(C, packed)]
pub struct UpdatePlane {
pub display_id: usize,