memory leak in lsort command
Closed / Fixed219038ffffffffffffffffffffffffffffffffffCreated 26 years agoUpdated 26 years ago
Descriptionplain2000-10-26 01:09:47
OriginalBugID: 4067 Bug
Version: 8.3b2
SubmitDate: '2000-01-24'
LastModified: '2000-01-25'
Severity: MED
Status: Released
Submitter: techsupp
ChangedBy: hobbs
OS: Linux
FixedDate: '2000-01-25'
FixedInVersion: 8.3
ClosedDate: '2000-10-25'
Name:
Philip Smolen
Comments:
I downloaded the latest source release, tcl8.3b2, just to see if the bug was still there. The bug was introducted in a much ealier version.
Note that TWO new objects are created each time. Fixing either of them caused the memory leak to grow half as quickly.
ReproducibleScript:
Tcl script: time {catch {lsort -command \{ {a b c}}} 100000
To start TCL: type tclsh or tcl from the Unix command propmt, or start Wish from the MS Windows start menu.
ObservedBehavior:
This is a memory leak. Each iteration creates two new tcl objects which are never recovered, wasting about 50 bytes per iteration. (The script above wastes about 5meg each time it is run.)
DesiredBehavior:
No memory leak. No appreciable change in memory usage, no matter how often the script is run. The lsort command should fail.
Patch:
diff -c tcl8.3b2/generic/tclCmdIL.c.orig tcl8.3b2/generic/tclCmdIL.c.fixed
*** tcl8.3b2/generic/tclCmdIL.c.orig Thu Jan 13 14:33:10 2000
--- tcl8.3b2/generic/tclCmdIL.c.fixed Mon Jan 24 00:25:08 2000
***************
*** 2601,2609 ****
*/
Tcl_Obj *newCommandPtr = Tcl_DuplicateObj(cmdPtr);
!
! if (Tcl_ListObjAppendElement(interp, newCommandPtr, Tcl_NewObj())
!= TCL_OK) {
return TCL_ERROR;
}
Tcl_ListObjAppendElement(interp, newCommandPtr, Tcl_NewObj());
--- 2601,2613 ----
*/
Tcl_Obj *newCommandPtr = Tcl_DuplicateObj(cmdPtr);
! Tcl_Obj *placeHolder = Tcl_NewObj();
! if (Tcl_ListObjAppendElement(interp, newCommandPtr, placeHolder)
!= TCL_OK) {
+ Tcl_IncrRefCount(newCommandPtr);
+ Tcl_DecrRefCount(newCommandPtr);
+ Tcl_IncrRefCount(placeHolder);
+ Tcl_DecrRefCount(placeHolder);
return TCL_ERROR;
}
Tcl_ListObjAppendElement(interp, newCommandPtr, Tcl_NewObj());
PatchFiles:
generic/tclCmdIL.c
Slightly modified patch applied for 8.3.0 (you can incr newCommandPtr
just after creation).
-- 01/25/2000 hobbs
welch Closed ticket [219038ffff].
[History diff]2000-10-26 08:34:05
Log in (anonymous is fine) to add a comment.