Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: e8092ab3fe378fd49fcc4d7ff1008900706a2583
Ticket: 1658572fffffffffffffffffffffffffffffffff
Heap corruption in interp.test
User & Date: twylite on 2007-03-15 23:19:56
Changes

  1. icomment:
    Logged In: YES 
    user_id=91629
    Originator: NO
    
    Just experienced this bug myself :(
    I'm building with Visual Studio 2005 Express, but I've also reproduced it with Visual Studio 6 Pro.  Operating system is Windows 2000 Professional.
    
    Build:
    Sources from CVS nightly 2007/03/08, and straight from CVS today (2007/03/15).
    nmake /nologo /f makefile.vc release OPTS=symbols,threads
    nmake /nologo /f makefile.vc test OPTS=symbols,threads
    
    Test:
    While running interp.test, tcltest.exe crashes (Access Violation error).
    
    Analysis:
    The problem is NOT in 2.13.  It is in the foreach + interp delete loop directly after 2.13.
    
    The crash occurs in Tcl_PopCallFrame() in tclnamesp.c, line 473: nsPtr->activationCount--;
    At this point nsPtr has the value 0x009ae728 (more on that later).
    
    The smallest code snippet that can reproduce this is:
    ---
    interp create
    interp create
    interp create
    interp create
    interp slaves
    # --> interp2 interp3 interp0 interp1
    interp delete interp2
    interp delete interp3
    ---
    
    Now, deleting the interps in anything but that order does not produce the bug.  I've tried every number of interps up to and including 4, and every order of deleting interps -- that's a LOT of combinations :( 
    
    Following the call chain down from the "interp delete interp3":
      Tcl_InterpObjCmd calls
      Tcl_DeleteCommandFromToken which invokes (*cmdPtr->deleteProc)(cmdPtr->deleteData) which is
      SlaveObjCmdDeleteProc which calls
      Tcl_DeleteInterp which calls
      Tcl_EventuallyFree which invokes (*freeProc)((char *)clientData) which is
      DeleteInterpProc which calls
      TclTeardownNamespace ...
      ... which overwrites memory at 0x009ae728 (and other locations)
    
    Digging deeper still ...
      TclTeardownNamespace calls
      TclDeleteNamespaceVars which invokes
      ckfree((char *) varPtr) ...
      ... which appears to corrupt 3 bytes at 0x009ae728
    
    The varPtr is no-where near 0x009ae728, nor (so far as I can tell) is any information contained in the varPtr struct.
    
    There are slightly differences in the corruption every time I look a little deeper down the stack -- I assume this may have something to do with the debugger having information in the stack frame.
    
    In any event, from 1 to 4 bytes of memory at 0x009ae728 get corrupted every time, to seemingly arbitrary values.
    
    Now I'm afraid I'm not familiar with the Tcl core, so the various structs here are meaningless to me.  Also my findings don't agree with mistachkin's conclusion about Tcl_UnsetVar called from Tcl_MakeSafe.
    
    But I'm going to go on a limb here and hazzard a guess:
    This bug only occurs with at least 4 interps, and only when you delete the 1st in the list returned by [interp slaves] followed by the second.  That list is not ordered; rather it looks to me like the interp names are kept in some sort of tree that is flattened by [interp slaves].  Is this possibly some sort of bug with deleting nodes from a tree, and more specifically when deleting variable names from the namespace's variable table?
    
    
    
  2. login: "twylite"
  3. mimetype: "text/plain"
  4. username: "twylite"