Skip to content
Tcl Source Code View Ticket
Login

View Ticket

cleanup after load from VFS

Closed / Fixed545579ffffffffffffffffffffffffffffffffffCreated 25 years agoUpdated 25 years ago
Descriptionplain2002-04-18 10:15:38
In tclIOUtil.c, there is extensive logic to load 
shared libs from VFS - even creating a temp copy (see 
Tcl_FSLoadFile).  Loading appears to work fine - the 
TclVFS extension does not override load, and things 
are ok with TclKit and Scripted Documents.

But unloading does not clean up such a temp file.  
After long term use, lots of "tclXXXXX" files can 
accumulate in /tmp (on Linux).

This can only be tested from a VFS-mounted FS, 
because normal loading surely loads as is, no copy 
made at all.  An example is to run tclkit with one of 
the scripted docs that contain a binary loaded 
extension - such as in http://www.equi4.com/pub/dok/.

Desired behavior: temp copy is deleted after use.

In fact, on Unix systems, one can probably delete 
right after loading - the temp copy does not need to 
exist when the shared library is in use.  This has as 
major benefit that aborts/crashes do not leave 
dangling files.

On Windows, the file cannot be deleted while in use.  
The least would be to delete on exit (as the unload 
logic in tclIOUtil.c appears to be intended).  If 
cleanup even with aborts are desired, then the 
Windows version may need to do special calls to 
register the files for cleanup on restart of Windows 
(not sure what the API is, or where, but it exists).

Windows may be harder - also because I'm not sure a 
DLL should be unloaded by Tcl (the usual reasons come 
to mind: C++ cleanup handling may not have occurred, 
and an atexit call into the lib may be pending).  If 
all else fails, then perhaps the only way out is to 
reuse a fixed set of file names for creating the temp 
copies ouf of VFS (tcl001.dll. tcl002.dll, etc) - so 
that at least names are re-used (and long term use do 
not lead to an unbounded number of copies).  Or Tcl 
could clean up its set of names on startup - multiple 
invocations are no problem, if the dll is still is 
use then the delete fails and can be ignored.

I'll be happy to help test the different scenario's, 
but I don't oversee all issues and the core code well 
enough to be able to code the solutions.  Besides, 
maybe it's almost there, just a few tweaks away from 
working just fine on Unix and Windows.
stevelplain2002-04-19 07:51:44
Logged In: YES 
user_id=2460

On MacOS X, a tmp directory is created (in the current 
directory) and not removed
nobodyplain2002-04-22 04:54:50
Logged In: NO 

There is logic in tclIOUtil.c to unload the file on exit 
(FSUnloadTempFile), so obviously something is happening to 
prevent that.  Perhaps you can have a look at what goes 
wrong?

If it appears to be an encoding problem, try 
moving 'TclFinalizeEncodingSubsystem()' to 
after 'TclFinalizeLoad()' in tclEvent.c (around line 816-
836).

No idea about stevel's 'tmp' directory either.
vincentdarleyplain2002-05-21 19:58:39
Logged In: YES 
user_id=32170

If you can delete the file immediately on Unix, you could 
try adding before this block of code:

/* 
 * When we unload this file, we need to 
divert the 
 * unloading so we can unload and cleanup 
the 
 * temporary file correctly.
 */
tvdlPtr = (FsDivertLoad*) ckalloc(sizeof
(FsDivertLoad));

in tclIOUtil.c (around line 2516), the following:

/* Try to delete the file immediately */
if (Tcl_FSDeleteFile(copyToPtr) == TCL_OK) {
    Tcl_DecrRefCount(copyToPtr);
    (*clientDataPtr) = NULL;
    (*unloadProcPtr) = NULL;
    return retVal;
}

for the problems on Windows, I suggest you put a breakpoint 
in FSUnloadTempFile and describe what goes wrong --- why 
the file isn't deleted.
vincentdarleyplain2002-05-21 23:53:03
Logged In: YES 
user_id=32170

note: for stevel's comment, this 'tmp' thing seems to be 
created by tcltest -- see bug 558742
jcwplain2002-05-22 03:20:04
Logged In: YES 
user_id=1983

Vince, thanks - your change works (I used the whole file you 
sent me).

As for the tmp/ dir, this used to be in the vfs.tcl (package 
vfslib), now no longer in tclvfs.  That issue should be gone 
in recent tclkits.
vincentdarley Closed ticket [545579ffff]. [History diff]2002-05-30 18:03:53
Log in (anonymous is fine) to add a comment.