Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: c8e1030c1a8a8560c2ecca6a76e56a98d0f3aa6c
Ticket: 219038ffffffffffffffffffffffffffffffffff
memory leak in lsort command
User & Date: nobody on 2000-10-26 01:09:47
Changes

  1. assignee changed to: "nobody"
  2. cmimetype changed to: "text/plain"
  3. comment changed to:
    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
    
  4. foundin changed to: "obsolete: 8.3b2"
  5. priority changed to: "5 Medium"
  6. resolution changed to: "None"
  7. status changed to: "Open"
  8. submitter changed to: "nobody"
  9. subsystem changed to: "10. Objects"
  10. title changed to: "memory leak in lsort command"
  11. type changed to: "Bug"