Skip to content

Commit d1530f0

Browse files
authored
Merge pull request rust-lang#3993 from RalfJung/dir-entry-drop-explicit
indicate more explicitly where we close host file/dir handles
2 parents d09fbe3 + df9829c commit d1530f0

File tree

1 file changed

+5
-2
lines changed
  • src/tools/miri/src/shims/unix

1 file changed

+5
-2
lines changed

src/tools/miri/src/shims/unix/fs.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ impl FileDescription for FileHandle {
149149
// to handle possible errors correctly.
150150
let result = self.file.sync_all();
151151
// Now we actually close the file and return the result.
152+
drop(*self);
152153
interp_ok(result)
153154
} else {
154155
// We drop the file, this closes it but ignores any errors
@@ -157,6 +158,7 @@ impl FileDescription for FileHandle {
157158
// `/dev/urandom` which are read-only. Check
158159
// https://github.com/rust-lang/miri/issues/999#issuecomment-568920439
159160
// for a deeper discussion.
161+
drop(*self);
160162
interp_ok(Ok(()))
161163
}
162164
}
@@ -1247,12 +1249,13 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
12471249
return this.set_last_error_and_return_i32(LibcError("EBADF"));
12481250
}
12491251

1250-
let Some(open_dir) = this.machine.dirs.streams.remove(&dirp) else {
1252+
let Some(mut open_dir) = this.machine.dirs.streams.remove(&dirp) else {
12511253
return this.set_last_error_and_return_i32(LibcError("EBADF"));
12521254
};
1253-
if let Some(entry) = open_dir.entry {
1255+
if let Some(entry) = open_dir.entry.take() {
12541256
this.deallocate_ptr(entry, None, MiriMemoryKind::Runtime.into())?;
12551257
}
1258+
// We drop the `open_dir`, which will close the host dir handle.
12561259
drop(open_dir);
12571260

12581261
interp_ok(Scalar::from_i32(0))

0 commit comments

Comments
 (0)