Crash (Tcl_Panic) when closing a file channel
I have created a file channel with an open file descriptor fd:
m_chan = Tcl_MakeFileChannel(fd, TCL_READABLE);
Later I'm closing the file channel, but at this time the file descriptor is already closed (the file descriptor comes from an external library):
Tcl_Close(NULL, m_chan);
Now in function PlatformEventsControl() [unix/tclEpollNotfy.c:245] Tcl_Panic() will be invoked, and my program is aborting. This behavior is new, and I think that this should not happen at all, all system functions are able to work with closed file descriptors (without aborting the program). Please note that in my case the file descriptor comes from an external library, so I have no control about it's state. Of course I could check the state before calling Tcl_Close(), but this is no solution, because how should I release the created channel when not with Tcl_Close()? Furthermore this behavior is incompatible to previous Tcl version 8.6.
Fixed by [5c274ca404] for [010d8f3885] (9.0.2): Tcl_Close() on a
file channel whose descriptor was already closed now returns "bad file
descriptor" instead of panicking. Tested with 9.0.1 (panic), 9.0.3 and 9.1.