From c682708127ffd746b0a5efe5d8c5cb7d0ead4990 Mon Sep 17 00:00:00 2001 From: tompro Date: Sat, 24 Feb 2024 17:30:51 +0100 Subject: [PATCH] fix memory leak --- src/kernel/src/kqueue/mod.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/kernel/src/kqueue/mod.rs b/src/kernel/src/kqueue/mod.rs index 36bf0768c..de925a9a5 100644 --- a/src/kernel/src/kqueue/mod.rs +++ b/src/kernel/src/kqueue/mod.rs @@ -5,7 +5,10 @@ use crate::{ process::{FileDesc, VThread}, syscalls::{SysErr, SysIn, SysOut, Syscalls}, }; -use std::{convert::Infallible, sync::Arc}; +use std::{ + convert::Infallible, + sync::{Arc, Weak}, +}; pub struct KernelQueueManager {} @@ -44,13 +47,13 @@ impl KernelQueueManager { #[derive(Debug)] pub struct KernelQueue { - filedesc: Arc, + filedesc: Weak, } impl KernelQueue { pub fn new(filedesc: &Arc) -> Arc { Arc::new(KernelQueue { - filedesc: filedesc.clone(), + filedesc: Arc::downgrade(filedesc), }) } } @@ -70,6 +73,6 @@ impl FileBackend for KernelQueue { _: TruncateLength, _: Option<&VThread>, ) -> Result<(), Box> { - Err(DefaultError::InvalidValue.into()) + Err(Box::new(DefaultError::InvalidValue)) } }