Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2003-05-10
06:38 • Closed ticket [731754ffff]: tls index leak/inconsistencies in tclThreadAlloc.c, ... artifact: 1670ce898e user: mistachkin
05:49 • Ticket [731754ffff]: 1 change artifact: 2d0c2fe37b user: mistachkin
2003-05-05
13:15 • Ticket [731754ffff]: 4 changes artifact: cf0145ee7c user: mistachkin
13:13 • Ticket [731754ffff]: 5 changes artifact: 523f75e6e0 user: mistachkin
2003-05-04
00:02 • Ticket [731754ffff]: 5 changes artifact: 45f80aabe9 user: msofer
2003-05-03
18:17 • Ticket [731754ffff]: 6 changes artifact: e251387b14 user: mistachkin
16:01 • Ticket [731754ffff]: 2 changes artifact: 7abdf9cba3 user: mistachkin
09:00 • New ticket [731754ffff]. artifact: d70f0147ba user: nobody

tls index leak/inconsistencies in tclThreadAlloc.c, etc

Closed / Fixed731754ffffffffffffffffffffffffffffffffffCreated 24 years agoUpdated 24 years ago
Descriptionplain2003-05-03 09:00:35
In the CVS HEAD version of tclThreadAlloc.c, near 
line #279, the following lines of code can be found:

#ifdef WIN32
    TlsFree((DWORD) cachePtr);
#else
    free(cachePtr);
#endif

After seeing this code and, I investigated it more 
carefully to see if I could more precisely figure out 
it's implications.  Here are my preliminary 
conclusions:

#1. It turns out that calling TlsFree on cachePtr is 
NOT correct.

#2. Calling free() on it produces a very strange 
crash in PutBlocks (null pointer dereference on line 
826).

#3. In an attempt to fix this problem, I moved the 
call to TlsFree to tclWinThrd.c, where it really 
belongs anyhow. However, calling TlsFree on 
the "key" static variable in this file, which is what 
cachePtr is based on, does not produce good 
results.

I am not sure how to fix this problem because I 
believe it may point to deeper issues with the 
threaded memory allocator. Any help on this issue, 
and more generally, my non-TLS patch, would be 
greatly appreciated.

If indeed TlsFree (or it's new non-TLS equivalent) 
must be called from tclThreadAlloc.c, it would 
make my patch a lot cleaner if TclFreeAllocCache 
called into a wrapper function residing in 
tclWinThrd.c, where I can use my new non-TLS 
thread storage subsystem if necessary.

JJM
mistachkin Ticket [731754ffff]: 2 changes [History diff]2003-05-03 16:01:56
mistachkinplain2003-05-03 18:17:53
Logged In: YES 
user_id=113501

Apparently, the TLS index for the threaded memory 
allocator is never freed.  Therefore, it is being leaked 
upon load/unload/reload of the Tcl DLL.
msoferplain2003-05-04 00:02:02
Logged In: YES 
user_id=148712

Back to Joe: I have no relevant knowledge on these matters :(
mistachkinplain2003-05-05 13:13:41
Logged In: YES 
user_id=113501

It appears, based on CVS history, that this is JeffH's 
area.  Assigning to him.
mistachkinplain2003-05-05 13:15:26
Logged In: YES 
user_id=113501

This bug is fixed in my Win32 NON-Tls thread storage 
patch.

patch #731356
mistachkin Ticket [731754ffff]: 1 change [History diff]2003-05-10 05:49:34
mistachkinplain2003-05-10 06:38:02
Logged In: YES 
user_id=113501

Memory leak fixed. all platforms now call:

free(cachePtr);

The more general problem of when to free the TLS index 
for the threaded memory allocator has been solved by 
my Win32 non-TLS patch.  However, I'm in the middle of 
reworking it to make it more modular before it's 
committed.
Log in (anonymous is fine) to add a comment.