Skip to content

Commit a680354

Browse files
committed
Don't let stdin/out/err close on drop.
1 parent f4b9cab commit a680354

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/lib.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,12 +207,17 @@ impl File {
207207
}
208208
}
209209

210-
impl core::ops::Drop for File {
210+
impl Drop for File {
211211
fn drop(&mut self) {
212212
let api = get_api();
213-
// We could panic on error, but let's silently ignore it for now.
214-
// If you care, call `file.close()`.
213+
// Don't close default (in, out, err) handles on drop because we can't
214+
// re-open them.
215+
if self.0.value() <= 2 {
216+
// don't close
217+
} else {
218+
// close it
215219
let _ = (api.close)(self.0);
220+
}
216221
}
217222
}
218223

0 commit comments

Comments
 (0)