Closed
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::close
method. - Change
PtyMaster
to wrap anOption<RawFd>
and have theclose
method set it toNone
. That way, thedrop
method will know whether to callclose
.
I prefer option 1, but I could go with any of these solutions.