Do not drop `Arc<dyn FileLike>` in an incorrect context

This commit is contained in:
Wang Siyuan 2025-11-06 11:31:41 +00:00 committed by Ruihan Li
parent e27b16ec4b
commit e336882eee
1 changed files with 7 additions and 9 deletions

View File

@ -179,13 +179,14 @@ impl SymOps for FileSymOps {
let thread = self.tid_dir_ops.thread();
let posix_thread = thread.as_posix_thread().unwrap();
let file = if let Some(file_table) = posix_thread.file_table().lock().as_ref()
&& let Ok(file) = file_table.read().get_file(self.file_desc)
{
file.clone()
} else {
return_errno_with_message!(Errno::ENOENT, "the file does not exist");
let file_table = posix_thread.file_table().lock();
let Some(file_table) = file_table.as_ref() else {
return_errno_with_message!(Errno::ENOENT, "the thread has exited");
};
let file_table = file_table.read();
let file = file_table
.get_file(self.file_desc)
.map_err(|_| Error::with_message(Errno::ENOENT, "the file does not exist"))?;
let path_name = if let Some(inode_handle) = file.downcast_ref::<InodeHandle>() {
inode_handle.path().abs_path()
@ -194,9 +195,6 @@ impl SymOps for FileSymOps {
String::from("/dev/tty")
};
// FIXME: This may not always be a suitable context to drop a `FileLike` object.
drop(file);
Ok(path_name)
}
}