Skip to content
Tcl Source Code History Of Ticket 219597
Login

History Of Ticket 219597

Artifacts Associated With Ticket 219597

  1. Ticket change [3b6091586a] (rid 112733) by msp on 2000-10-28 01:53:46:

    1. assignee initialized to: "nobody"
    2. cmimetype initialized to: "text/plain"
    3. comment initialized to:
      I've noticed some strange memory leaks using
      info exists on arrays.The leak is also present in 8.3.1.
      I'm running Tcl on Linux. The below scripts demonstrate
      the memory leak.
      
      # this leaks big time
      
      proc main {argv} {
          expr {srand([clock clicks])}
      
          for {set i 0} {$i < 1000} {incr i} {
      set n1 [expr {int(rand() * 1000)}]
      set n2 [expr {int(rand() * 1000)}]
      set x($n1,$n2) 0
          }
      
          while {1} {
      set n1 [expr {int(rand() * 1000)}]
      set n2 [expr {int(rand() * 1000)}]
      
      if {[info exists x($n1,$n2)]} {
          incr x($n1,$n2)
      }
          }
      }
      
      # no leak
      
      proc main2 {argv} {
          expr {srand([clock clicks])}
      
          for {set i 0} {$i < 1000} {incr i} {
      set n1 [expr {int(rand() * 1000)}]
      set n2 [expr {int(rand() * 1000)}]
      set x($n1,$n2) 0
          }
      
          while {1} {
      set n1 [expr {int(rand() * 1000)}]
      set n2 [expr {int(rand() * 1000)}]
      
      catch {
          incr x($n1,$n2)
      }
          }
      }
      
      # no leak
      
      proc main3 {argv} {
          expr {srand([clock clicks])}
      
          for {set i 0} {$i < 1000} {incr i} {
      set n1 [expr {int(rand() * 1000)}]
      set x($n1) 0
          }
      
          while {1} {
      set n1 [expr {int(rand() * 1000)}]
      
      if {[info exists x($n1)]} {
          incr x($n1)
      }
          }
      }
      
    4. foundin initialized to: "obsolete: 8.4a1"
    5. priority initialized to: "5 Medium"
    6. resolution initialized to: "None"
    7. status initialized to: "Open"
    8. submitter initialized to: "msp"
    9. subsystem initialized to: "07. Variables"
    10. title initialized to: "Memory leak with info exists and arrays"
    11. type initialized to: "Bug"
  2. Ticket change [7cc84af0ee] (rid 97136) by hobbs on 2000-11-02 04:18:24:

    1. closedate changed to: "2000-11-01T21:18:24"
    2. closer changed to: "hobbs"
    3. icomment:
      Dup of 119213, fixed for 8.4a2.
      
      jupiter [~/cvs/tcl8.4] 191 % cvs diff -bc generic/tclVar.c 
      Index: generic/tclVar.c
      ===================================================================
      RCS file: /home/cvs/external/tcl/generic/tclVar.c,v
      retrieving revision 1.23
      diff -b -c -r1.23 tclVar.c
      *** tclVar.c    2000/08/25 20:39:31     1.23
      --- tclVar.c    2000/11/01 21:16:47
      ***************
      *** 4863,4869 ****
        {
            Var *varPtr;
            Var *arrayPtr;
      -     char *msg;
        
            /*
             * The choice of "create" flag values is delicate here, and
      --- 4863,4868 ----
      ***************
      *** 4876,4892 ****
             */
        
            varPtr = TclLookupVar(interp, varName, (char *) NULL,
      !             0, "access",
      !             /*createPart1*/ 0, /*createPart2*/ 1, &arrayPtr);
            if (varPtr == NULL) {
              return NULL;
            }
      !     if ((varPtr != NULL) &&
      !           ((varPtr->tracePtr != NULL)
      !           || ((arrayPtr != NULL) && (arrayPtr->tracePtr != NULL)))) {
      !       msg = CallTraces((Interp *)interp, arrayPtr, varPtr, varName,
                      (char *) NULL, TCL_TRACE_READS);
      !       if (msg != NULL) {
                  /*
                   * If the variable doesn't exist anymore and no-one's using
                   * it, then free up the relevant structures and hash table entries.
      --- 4875,4892 ----
             */
        
            varPtr = TclLookupVar(interp, varName, (char *) NULL,
      !             0, "access", /*createPart1*/ 0, /*createPart2*/ 1, &arrayPtr);
      ! 
            if (varPtr == NULL) {
              return NULL;
            }
      ! 
      !     if ((varPtr->tracePtr != NULL)
      !           || ((arrayPtr != NULL) && (arrayPtr->tracePtr != NULL))) {
      !       CallTraces((Interp *)interp, arrayPtr, varPtr, varName,
                      (char *) NULL, TCL_TRACE_READS);
      !     }
      ! 
            /*
             * If the variable doesn't exist anymore and no-one's using
             * it, then free up the relevant structures and hash table entries.
      ***************
      *** 4894,4902 ****
        
                  if (TclIsVarUndefined(varPtr)) {
                      CleanupVar(varPtr, arrayPtr);
      -           }
                  return NULL;
      -       }
            }
            return varPtr;
        }
      --- 4894,4901 ----
        
            if (TclIsVarUndefined(varPtr)) {
              CleanupVar(varPtr, arrayPtr);
              return NULL;
            }
      + 
            return varPtr;
        }
      
      
      
    4. login: "hobbs"
    5. mimetype: "text/plain"
    6. resolution changed to: "Duplicate"
    7. status changed to: "Closed"
    8. username: "hobbs"