Tcl Source Code

View Ticket
Login
Bounty program for improvements to Tcl and certain Tcl packages.
Ticket UUID: 80304238ac5310b259c79c546d36d790c2a1d39e
Title: foreach memleak
Type: Bug Version: trunk
Submitter: dgp Created on: 2016-02-25 20:18:21
Subsystem: 16. Commands A-H Assigned To: dgp
Priority: 5 Medium Severity: Severe
Status: Closed Last Modified: 2016-03-01 16:56:18
Resolution: Fixed Closed By: dgp
    Closed on: 2016-03-01 16:56:18
Description:
This script leaks 48 bytes:

proc doit script {
    eval $script
    set index xx
}
doit {foreach index foo {}}

This leak is what prevents me getting
a clean valgrind of our release candidates
because my system has an install of "nsf 2.0.0"
and it has code like this in its
pkgIndex.tcl file.  This solves the mystery of
why others see clean valgrind runs and I do not.
User Comments: dgp added on 2016-03-01 16:56:18:
Fix merged to trunk.

Same demo script does not leak in 8.5.19.

Either no leak there, or no reliabale way to
demo it (yet). Either way, doing nothing on
8.5 branch.

dgp added on 2016-02-26 15:44:22:
See bug-80304238ac branch for candidate fix.

dgp added on 2016-02-26 04:10:37:
It appears that this code is a nasty way to create
a circular reference, where each of 2 Tcl_Obj values
holds a reference to the other as part of its intrep.
This defeats the refCounting system, and the
objects leak.

The cross referencing comes between a "list"
value with a single element which is a "localVarName"
value with a cached localName (twoPtrValue.ptr1)
which is the original list value.