Tcl Source Code

View Ticket
Login
Ticket UUID: 3614226
Title: Memory leaks in compiled code
Type: Bug Created on: 2013-06-01 21:03:55
Submitter: dkf Assigned to: dkf
Subsystem: 47. Bytecode Compiler Severity:
Priority: 8 Last modified: 2013-06-05 15:13:37
Status: Closed Closed by: dkf
Resolution: Fixed Closed on: 2013-06-05 08:13:37
Version: current: 8.6.0
Description:
This procedure leaks memory when run (or would if it didn't crash):

    proc foo {} {while 1 {list a [list b [continue]]}}

The problem? The INST_CONTINUE doesn't clear things down. (This is a general problem if we've got a [return -code continue]; this is all work-in-progress.) So we add tracking of stack depth (dkf-compile-improvements branch) so we can issue the right number of INST_POPs and it hangs without memory consumption, absolutely correctly. Yay!

Let's try in our enhanced code with a new procedure:

    proc foo {} {while 1 {puts {*}[puts {*}[continue]]}}

This is now worse; it leaks memory like it is going out of fashion! The problem is that we've got a build-up on the TD->auxObjList that can't be cleared.

I've not analyzed what happens when there's a [catch] involved.
User Comments:
dkf added on 2013-06-03 16:39:22:
Note that returning from the stack frame (strictly, the bytecode execution context) releases the "leaking" memory so this is strictly not a leak. Just behaves like one.

Tests for the various cases (both normal stack and expansion stack, both [break] and [continue]) discussed on the branch.

dkf added on 2013-06-05 15:13:37:

allow_comments - 1

Fixed on trunk; will not backport as new opcode was required.

Case with [catch] still needs to be analyzed, but that can be its own bug report if necessary.