Skip to content
Tcl Source Code View Ticket
Login

View Ticket

Tcl_EvalObjv leaks memory when calling apply

Closed / Fixed1578454fffffffffffffffffffffffffffffffffCreated 20 years agoUpdated 20 years ago
Descriptionplain2006-10-16 19:44:46
When apply is called using Tcl_EvalObjv, memory is 
being leaked that doesn't seem possible to reclaim.
If puts is used as command instead of apply no memory 
is lost. 
Attached a small C lib which defines two commands 
doputs and doapply where the only difference is the 
contents of objv[0] in the Tcl_EvalObjv call. doapply 
leaks, doputs doesn't.

System info:

% parray tcl_platform
tcl_platform(byteOrder) = littleEndian
tcl_platform(machine)   = intel
tcl_platform(os)        = Windows NT
tcl_platform(osVersion) = 5.1
tcl_platform(platform)  = windows
tcl_platform(threaded)  = 1
tcl_platform(user)      = mjanssen
tcl_platform(wordSize)  = 4
% info patchlevel
8.5a5
mpc_janssenplain2006-10-17 02:44:46
File Added - 198467: apply.zip
mpc_janssenplain2006-10-17 02:58:30
Logged In: YES 
user_id=1463011

Attached the memory trace for the following script:

memory trace on
load leak.dll

time {
    doapply
} 5

A quick glance seems to indicate that memory allocated in 
tclCompile.c 1706 is only sparingly freed:

> cat mem.out | grep 124
ckalloc 995860 124 ..\generic\tclCompile.c 1706
ckalloc 995cc0 124 ..\generic\tclCompile.c 1706
ckalloc 996850 124 ..\generic\tclCompile.c 1706
ckalloc 9966b0 124 ..\generic\tclCompile.c 1706
ckalloc 9964e0 124 ..\generic\tclCompile.c 1706
ckalloc 996310 124 ..\generic\tclCompile.c 1706
ckfree 995860 124 ..\generic\tclCompile.c 749
ckalloc 993ad0 124 ..\generic\tclCompile.c 1706
mpc_janssenplain2006-10-17 02:58:31
File Added - 198471: mem.out
msoferplain2006-10-17 03:11:10
Logged In: YES 
user_id=148712

New test added to show the leak of the internal rep:

==== apply-9.1 leaking internal rep FAILED
==== Contents of test case:

    set end [getbytes]
    for {set i 0} {$i < 5} {incr i} {
        ::apply [lrange $lam 0 end]
        set tmp $end
        set end [getbytes]
    }
    set leakedBytes [expr {$end - $tmp}]

---- Result was:
222
---- Result should have been (exact matching):
0
==== apply-9.1 FAILED
msofer Ticket [1578454fff]: 1 change [History diff]2006-10-17 03:11:33
msoferplain2006-10-17 03:40:26
Logged In: YES 
user_id=148712

Fixed in HEAD; thanks
msofer Ticket [1578454fff]: 3 changes [History diff]2006-10-17 03:40:27
Log in (anonymous is fine) to add a comment.

Attachments: