Artifacts Associated With Ticket a3309d01dbb0f23c
Ticket change [14ec51bcaf] (rid 142515) by bovine on 2015-07-15 22:50:54:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/plain"
- comment initialized to:
I've discovered a memory leak in Tcl 8.6.4 on FreeBSD 9.1 and 10.1 with the following script. The leak does not occur under Tcl 8.5 https://gist.github.com/bovine/15c350d044325a93d5cb The issue seems to be specific to using lists that are built up using "lappend". If $foo is using a list that is directly "set" in a single operation, then the leak does not appear to occur. Additionally, the leak occurs when using "unset" to remove individual elements from myarray. If you "array unset myarray" entirely, then the memory seems to be properly freed.
- foundin initialized to: "8.6.4"
- is_private initialized to: "0"
- login: "bovine"
- priority initialized to: "5 Medium"
- private_contact initialized to: "f0e2312a244c99b69b66ff52a743015292c5af63"
- resolution initialized to: "None"
- severity initialized to: "Severe"
- status initialized to: "Open"
- submitter initialized to: "bovine"
- subsystem initialized to: "14. List Object"
- title initialized to: "Leak in array when using generated lists as keys"
- type initialized to: "Bug"
Add attachment "gistfile1.tcl" [002f10dd54] (rid 142517) by msofer on 2015-07-15 23:00:18.
Add attachment "gistfile1.tcl" [e562b7832c] (rid 142518) by aku on 2015-07-15 23:09:36.
Ticket change [9ee86232c7] (rid 142519) by aku on 2015-07-15 23:10:10:
- comment changed to:
I've discovered a memory leak in Tcl 8.6.4 on FreeBSD 9.1 and 10.1 with the following script. The leak does not occur under Tcl 8.5 https://gist.github.com/bovine/15c350d044325a93d5cb -- attached The issue seems to be specific to using lists that are built up using "lappend". If $foo is using a list that is directly "set" in a single operation, then the leak does not appear to occur. Additionally, the leak occurs when using "unset" to remove individual elements from myarray. If you "array unset myarray" entirely, then the memory seems to be properly freed.
- icomment: "gist extracted and attached."
- login: "aku"
- mimetype: "text/plain"
- comment changed to:
Add attachment "memleak-bovine.tcl" [46a84b1b2d] (rid 142520) by aspect on 2015-07-15 23:59:10.
Add attachment "meminfo.tcl" [05fbf4f240] (rid 142521) by aspect on 2015-07-15 23:59:46.
Ticket change [3355113d73] (rid 142522) by aspect on 2015-07-16 00:04:47:
- icomment:
Just playing around with this on the script level, I've been able to simplify the test to the attached memleak-bovine.tcl + meminfo.tcl. Output shows allocated bytes increasing by ~900 each 5 iterations, and (total mallocs-total frees) increasing by 25 - this all after the array is "full" and elements are being deleted. Note this test doesn't require [lappend]. The dependency on [unset myarray($key)] is genuine -- using [array unset myarray $key] fails to exhibit the leak. Other variations: 1. moving the entire body of [doit] into the loop at global scope doesn't leak 2. moving the body of [doit] into the loop and wrapping it in a proc leaks 3. making myarray proc-local instead of global leaks
- login: "aspect"
- mimetype: "text/plain"
- username: "aspect"
- icomment:
Ticket change [f625c5d424] (rid 142523) by aspect on 2015-07-16 03:22:29:
- icomment:
The following patch seems to fix this issue without breaking existing tests. It's a bit brutish - a more sensitive patch would more closely compare this bytecoded INST_UNSET_ARRAY code with ArrayUnsetCmd(). Bug seems to have existed since 8.6.2, so I guess it's been in the bytecode all along. Index: generic/tclExecute.c ================================================================== --- generic/tclExecute.c +++ generic/tclExecute.c @@ -4178,11 +4178,11 @@ * No nasty traces and element exists, so we can proceed to * unset it. Might still not exist though... */ if (!TclIsVarUndefined(varPtr)) { - TclDecrRefCount(varPtr->value.objPtr); + TclPtrUnsetVar(interp, varPtr, arrayPtr, NULL, part2Ptr, flags, opnd); } else if (flags & TCL_LEAVE_ERR_MSG) { goto slowUnsetArray; } varPtr->value.objPtr = NULL; TRACE_APPEND(("OK\n")); - login: "aspect"
- mimetype: "text/plain"
- icomment:
Ticket change [e0264a0112] (rid 142524) by bovine on 2015-07-16 04:03:47:
- login: "bovine"
- mimetype: "text/plain"
- subsystem changed to: "07. Variables"
- title changed to: "Leak in array when unsetting keys from a proc"
Ticket change [bb7a4cba67] (rid 142530) by dgp on 2015-07-17 19:34:00:
- icomment:
See branch bug-a3309d01db for conventional test that demos the leak. Branches off the checkin that bisecting determines is the cause of the leak.
- login: "dgp"
- mimetype: "text/plain"
- icomment:
Ticket change [0bdb482a62] (rid 142550) by dgp on 2015-07-18 05:54:17:
- assignee changed to: "dgp"
- closedate changed to: "2457221.74603666"
- closer changed to: "dgp"
- icomment:
Fix merged to trunk.
- login: "dgp"
- mimetype: "text/plain"
- resolution changed to: "Fixed"
- status changed to: "Closed"