-
Couldn't load subscription status.
- Fork 716
Closed
Labels
Description
PtyMaster implements Drop to close its RawFd. However, it ignores errors, because the caller may have manually closed the RawFd. This is bad, because it can lead to double closes, like this:
{
let m = posix_openpt(O_RDWR); # Creates a pty with file descriptor 3
close(m.master); # Close file descriptor 3
let f = std::fs::File::create("foo"); # Creates a file with file descriptor 3
} # PtyMaster::Drop closes file descriptor 3
f.write("whatever"); # fails with EBADF
There are three possible solutions:
- Always check for errors in
PtyMaster::Drop - Don't implement
PtyMaster::Drop; make the caller responsible for closing it. If we go this route, we should also add aPtyMaster::closemethod. - Change
PtyMasterto wrap anOption<RawFd>and have theclosemethod set it toNone. That way, thedropmethod will know whether to callclose.
I prefer option 1, but I could go with any of these solutions.