Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2012-04-24
23:41 • Closed ticket [1603234fff]: Memory leak with thread::transfer plus 7 other c... artifact: ea2c58e71f user: dgp
23:01 • Ticket [1603234fff]: 6 changes artifact: 24df9eb491 user: dgp
2007-06-05
04:02 • Ticket [1603234fff]: 4 changes artifact: b38e6e769e user: oleg_derevenetz
2007-01-20
01:42 • Ticket [1603234fff]: 4 changes artifact: 413ee49b1e user: vasiljevic
2006-12-01
06:33 • Ticket [1603234fff]: 4 changes artifact: 399d62856f user: nobody
05:01 • Ticket [1603234fff]: 4 changes artifact: 65273c5d62 user: hobbs
2006-11-26
22:22 • Ticket [1603234fff]: 4 changes artifact: 7a7fb1cfb4 user: nobody
15:21 • New ticket [1603234fff]. artifact: 1cd76cc2d6 user: nobody

Memory leak with thread::transfer

Closed / Fixed1603234fffffffffffffffffffffffffffffffffCreated 20 years agoUpdated 15 years ago
Descriptionplain2006-11-26 15:21:00
I am developing project using Tcl + Thread (BitTorrent tracker). At first I tried to use model where main thread after accepting new connection (using 
socket -server) transfers connection socket to free thread using thread::transfer. But testing of this model reveals slow memory leak (about 1Mb/5min with requests rate about 100 req/sec). Using Tcl memory debugging (Tcl and Thread built with --enable-symbols=mem) and memory command I found that memory leaks after each thread::transfer call. This observes on latest Tcl/Threads versions as well (tcl8.4.14 and thread2.6.5) compiled on Solaris 9/i386 using GCC 3.3.2.

Is this a known issue ? Is thread::transfer requires some extra dealing with transferred filedescriptors before or after transfer ?

This is a small test:

#!/usr/local/bin/tclsh

package require Thread

proc transfer {channel} {
    global tid

    puts [memory info]
    thread::transfer $tid $channel
    thread::send -async $tid "close $channel"
}

proc accept {channel client_addr client_port} {
    after idle [list transfer $channel]
}

set tid [thread::create -joinable thread::wait]

socket -server accept 9999

thread::wait

Field "current bytes allocated" increased by 32 bytes after each incoming connection.
nobodyplain2006-11-26 22:22:16
Logged In: NO 

Sorry, I forgot to include a e-mail. My e-mail is [email protected].
hobbsplain2006-12-01 05:01:48
Logged In: YES 
user_id=72656
Originator: NO

I am not able to repro this bug using valgrind 3.2.1 on Linux x64.  Perhaps it is because it is being properly freed at exit, just not in the interim use?
nobodyplain2006-12-01 06:33:51
Logged In: NO 

So "current bytes allocated" output by [memory info] doesn't increase after each new connection in your tests ?
vasiljevicplain2007-01-20 01:42:02
Logged In: YES 
user_id=95086
Originator: NO

What you experience might be a problem in Tcl core
that badly handles std channels. I'm loking at that
at this moment.

It appears to leak std channels on every thread 
creation and exit. I haven't examined your code
but will do that later on when I find out what the
damn is happening with those channels and why do
they leak.

This is considered to be a very problematic point
in Tcl design (handling of std channels when 
building thread-enabled Tcl library).
oleg_derevenetzplain2007-06-05 04:02:49
Logged In: YES 
user_id=1654299
Originator: NO

vasiljevic, if this issue will be resolved some day - it will be good. Are there any solutions or recommendations for this case now ?
dgpplain2012-04-24 23:01:37
Problem is that ThreadTransfer() doesn't free
the resultPtr that it allocs.
dgpplain2012-04-24 23:41:00
allow_comments - 1


Fixed for Thread 2.6.8+.
Log in (anonymous is fine) to add a comment.