Tcl Source Code

View Ticket
Login
Ticket UUID: 3554250
Title: [exit]->close2proc->Tcl_FSDeleteFile == segfault
Type: Bug Version: obsolete: 8.5.12
Submitter: stwo Created on: 2012-08-04 12:17:45
Subsystem: 37. File System Assigned To: dgp
Priority: 7 High Severity:
Status: Closed Last Modified: 2012-08-07 22:28:23
Resolution: Fixed Closed By: dgp
    Closed on: 2012-08-07 15:28:23
Description:
Tcl_FSDeleteFile will segfault if called from a channel's close2proc when the interpreter [exit]s but not when the main window is destroyed when running wish.
This used to work; something changed between 8.5.11 and 8.5.12.
User Comments: dgp added on 2012-08-07 22:28:23:

allow_comments - 1

Fix committed to 8.5 and trunk branches.

dgp added on 2012-08-07 22:20:54:
Got a fix.

stwo added on 2012-08-07 22:17:43:
I've switched to using unlink(2) so this is no longer affecting me.
If it's not a bug, as ferrieux says, then I guess close this ticket and unburden dgp a tad. :) I realize this is a difficult area of the code to be working in.

dgp added on 2012-08-07 21:04:26:
Digging further into the feature branch, the failure
appears in http://core.tcl.tk/tcl/info/223bd04c8b

dgp added on 2012-08-07 20:54:25:
First broken in http://core.tcl.tk/tcl/info/575001f433
so I'm to blame.

ferrieux added on 2012-08-05 21:55:02:
To elaborate: the FS finalization part is registered as an (early) exit handler, and as such is run before IO finalization (the idea being that tyipcal exit handlers might do some IO). In some cases (like flushing a zipped rw filesystem) it is good to do things in this order, so let's not change it.

Hence I guess the proper fix is along the lines sketched before (robustize flagging).

ferrieux added on 2012-08-05 21:42:58:
Okay, this (in current 8.6 at least) is the result of the finalization sequence nuking the FS part before the IO part:
FsThrExitProc called before FinalizeIOSubsystem, which calls the tested close2proc.

One has to choose an order, this one is not worse than another (or is it ?). I guess we could make better use of finalization flags to detect this kind of after-death use of an API though.

More diggin needed to figure out why it worked in 8.5.11.

ferrieux added on 2012-08-05 21:30:41:
Hum, strike that, had not uncommented the proper line :}

ferrieux added on 2012-08-05 21:29:29:
Also, the code mentions failing in 8.6 but I cannot reproduce, even with TCL_FINALIZE_ON_EXIT.
Any details on the configure flags ?

dkf added on 2012-08-05 21:02:49:
It would be nice to reproduce without C code. (Don't know if that's possible, or if running inside an exit handler is critical.)

stwo added on 2012-08-05 02:27:53:
Attached a program that demonstrates the problem.

stwo added on 2012-08-05 02:27:22:

File Added - 450553: c.c

Attachments: