Skip to content

Commit d7967f6

Browse files
committed
Drop files explicitly when closing them
1 parent 260b463 commit d7967f6

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/shims/fs.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
143143
let fd = this.read_scalar(fd_op)?.to_i32()?;
144144

145145
if let Some(handle) = this.machine.file_handler.handles.remove(&fd) {
146-
this.try_unwrap_io_result(handle.file.sync_all().map(|_| 0i32))
146+
// `File::sync_all` does the checks that are done when closing a file. We do this to
147+
// to handle possible errors correctly.
148+
let result = this.try_unwrap_io_result(handle.file.sync_all().map(|_| 0i32));
149+
// Now we actually drop the handle.
150+
drop(handle);
151+
// And return the result.
152+
result
147153
} else {
148154
this.handle_not_found()
149155
}

0 commit comments

Comments
 (0)