Skip to content

Commit

Permalink
Merge pull request rust-lang#3993 from RalfJung/dir-entry-drop-explicit
Browse files Browse the repository at this point in the history
indicate more explicitly where we close host file/dir handles
  • Loading branch information
RalfJung authored Oct 26, 2024
2 parents d09fbe3 + df9829c commit d1530f0
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/tools/miri/src/shims/unix/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ impl FileDescription for FileHandle {
// to handle possible errors correctly.
let result = self.file.sync_all();
// Now we actually close the file and return the result.
drop(*self);
interp_ok(result)
} else {
// We drop the file, this closes it but ignores any errors
Expand All @@ -157,6 +158,7 @@ impl FileDescription for FileHandle {
// `/dev/urandom` which are read-only. Check
// https://github.com/rust-lang/miri/issues/999#issuecomment-568920439
// for a deeper discussion.
drop(*self);
interp_ok(Ok(()))
}
}
Expand Down Expand Up @@ -1247,12 +1249,13 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
return this.set_last_error_and_return_i32(LibcError("EBADF"));
}

let Some(open_dir) = this.machine.dirs.streams.remove(&dirp) else {
let Some(mut open_dir) = this.machine.dirs.streams.remove(&dirp) else {
return this.set_last_error_and_return_i32(LibcError("EBADF"));
};
if let Some(entry) = open_dir.entry {
if let Some(entry) = open_dir.entry.take() {
this.deallocate_ptr(entry, None, MiriMemoryKind::Runtime.into())?;
}
// We drop the `open_dir`, which will close the host dir handle.
drop(open_dir);

interp_ok(Scalar::from_i32(0))
Expand Down

0 comments on commit d1530f0

Please sign in to comment.