Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: cf8645dafd7a760d297205f263e755a53c6bdde4
Ticket: 218982ffffffffffffffffffffffffffffffffff
Unsetting array with element traces causes Tcl to abort
User & Date: nobody on 2000-10-26 01:08:55
Changes

  1. assignee changed to: "nobody"
  2. cmimetype changed to: "text/plain"
  3. comment changed to:
    OriginalBugID: 3453 Bug
    Version: 8.0p2
    SubmitDate: '1999-11-05'
    LastModified: '2000-01-14'
    Severity: MED
    Status: Released
    Submitter: techsupp
    ChangedBy: ericm
    OS: Solaris
    OSVersion: 2.6
    FixedDate: '2000-01-14'
    FixedInVersion: 8.3
    ClosedDate: '2000-10-25'
    
    
    Name:
    Mark A. Wege
    
    Comments:
    The code also fails under Tcl 7.4.
        
    The code does NOT fail if the array variable is unset in a procedure
    instead of the global scope.  It also doesn't fail if you remove the
    global statement from the showtrace procedure.
    
    ReproducibleScript:
    The following script is a part of some code I've written to help people
    track down problems in their code by setting traces on variables to see
    where their values are being changed.  To execute this, either execute
    tclsh interactively and paste this code into the session, or place the
    code into a file and then execute tclsh with the file as a parameter:
    
    proc showtrace {var ind op} {
        global t
        puts "showtrace: var = $var   ind = $ind   op = $op"
    }
    set t(1) 1
    trace variable t(1) u showtrace
    unset t
    
    ObservedBehavior:
    When the code is executed, tclsh provides the following output and
    then crashes:
        
    showtrace: var = t   ind = 1   op = u
    malformed bucket chain in Tcl_DeleteHashEntry
    Abort (core dumped)
    
    DesiredBehavior:
    Tcl should be able to unset the array variable without crashing.
    
    
    Confirmed in 8.2.2.  Workaround is to explicitly unset t(1)
    first (or foreach over array names). 
    -- 11/10/1999 hobbs
    
    The root of this problem had to do with a failure to protect the array variable from being deleted multiple times, which was implicitly happening in the code shown:  once for the unset, and once when the call stack was popped after finishing the showtrace function.  Of course, free'ing a block of memory twice is never a good thing, and this ultimately led to the core dump.
    
    I fixed the bug by putting protection against this situation in the unset code.  The fix will go into 8.3.
    - eric
    
    -- 01/14/2000 ericm
    
    
    
  4. foundin changed to: "obsolete: 8.0p2"
  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: "07. Variables"
  10. title changed to:
    Unsetting array with element traces causes Tcl to abort
    
  11. type changed to: "Bug"