Tcl Source Code

View Ticket
Login
Ticket UUID: 1578454
Title: Tcl_EvalObjv leaks memory when calling apply
Type: Bug Version: obsolete: 8.5a5
Submitter: mpc_janssen Created on: 2006-10-16 19:44:46
Subsystem: 42. Memory Preservation Assigned To: msofer
Priority: 9 Immediate Severity:
Status: Closed Last Modified: 2006-10-17 03:40:27
Resolution: Fixed Closed By: msofer
    Closed on: 2006-10-16 20:40:27
Description:
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
User Comments: msofer added on 2006-10-17 03:40:26:
Logged In: YES 
user_id=148712

Fixed in HEAD; thanks

msofer added on 2006-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

mpc_janssen added on 2006-10-17 02:58:31:

File Added - 198471: mem.out

mpc_janssen added on 2006-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_janssen added on 2006-10-17 02:44:46:

File Added - 198467: apply.zip

Attachments: