Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2026-10-22
17:19 • Ticket [b0e16e3f34] Crash (Tcl_Panic) when closing a file channel status sti... artifact: 9ef57781b7 user: serhiy.storchaka
2026-10-12
19:33 • Closed ticket [b0e16e3f34]. artifact: 23870dbbb8 user: serhiy.storchaka
2017-08-11
15:46 • New ticket [b0e16e3f34]. artifact: d84ab85194 user: gcramer

Crash (Tcl_Panic) when closing a file channel

Closed / Fixedb0e16e3f34ff4c76c1177126380e9fb0d7535d49Created 9 years agoUpdated 41 days ago
Descriptionhtml2017-08-11 15:46:05

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.

serhiy.storchakawiki2026-10-12 19:33:22

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.

serhiy.storchaka Ticket [b0e16e3f34]: 3 changes [History diff]2026-10-22 17:19:25
Log in (anonymous is fine) to add a comment.