Skip to content
Tcl Source Code View Ticket
Login

View Ticket

Leaking Open File Handles

Closed / Invalid458490ffffffffffffffffffffffffffffffffffCreated 25 years agoUpdated 25 years ago
Descriptionplain2001-09-04 19:08:47
Hi All, 

I create an interpreter from "C" evaluate the 
following script: 

set F [open $rep_file w] puts invalid_file_ptr 
this_causes_an_error close $F 

Because an error occurs in the "puts" the "close $F" 
does not get called during script evaluation. 

Opening the file up with Wordpad gives the "File in 
use by another application." Note that win-emacs can 
open the file so it is a windows open exclusive type 
open that gives the error. 

After reporting the error, the "C" then code deletes 
the interpreter but still the file handle must be open 
because Wordpad still cannot open. I have also tried 
calling this directly before and after deleting the 
Interpreter: 

Tcl_DeleteAssocData(gpInterp, "tclIO"); 

But it has no effect either. :(. 

I have verified this bug to exist in 8.0 8.3 and 8.4 

Can anyone provide workaround. Do I have to 
trap "open's" and "close's" myself? 

Note that replacing the illegal "puts" statement with 
a "return" actually has the same effect. 

Of course exiting the process closes the handle and 
wordpad is able to open the file. 

Thanks,

Chris
crokusekplain2001-09-05 04:17:31
Logged In: YES 
user_id=315927

The script should read:

set F [open $rep_file w] 
puts invalid_file_ptr this_causes_an_error 
close $F 

OR

set F [open $rep_file w] 
return
close $F
hobbsplain2001-09-05 04:32:33
Logged In: YES 
user_id=72656

You can't just init and delete the single interp (channels 
can be moved between interps and threads).  You need to 
make sure Tcl_Finalize is called (which in turn calls 
TclFinalizeIOSubsystem which actually ensures all channels 
are closed).
Log in (anonymous is fine) to add a comment.