Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: c8b27d297f7626715525d0288371fb458bf550cf
Ticket: 219393ffffffffffffffffffffffffffffffffff
[trace] should use Tcl_Preserve()
User & Date: nobody on 2000-10-26 05:12:17
Changes

  1. assignee changed to: "nobody"
  2. cmimetype changed to: "text/plain"
  3. comment changed to:
    OriginalBugID: 6172 Bug
    Version: 8.3.2
    SubmitDate: '2000-08-25'
    LastModified: '2000-09-05'
    Severity: CRIT
    Status: UnAssn
    Submitter: techsupp
    ChangedBy: ericm
    OS: Linux-Red Hat
    FixedDate: '2000-10-25'
    ClosedDate: '2000-10-25'
    
    
    Name:
    
    Don Porter
    
    
    
    Comments:
    
    The same problem exists in the Tcl 8.4 branch,
    
        and should be corrected there too.
    
    
    
    ReproducibleScript:
    
    # FILE: demo.tcl
    
    proc Hare {old args} {
    
        trace vdelete ::bunny w [list Hare $old]
    
        trace variable ::bunny w [list Hare $::bunny]
    
        error "FOO"
    
    }
    
    set bunny Bugs
    
    trace variable bunny w [list Hare $bunny]
    
    while {1} {catch { set bunny Easter}}
    
    
    
    ObservedBehavior:
    
    $ tclsh demo.tcl
    
    Segmentation fault (core dumped)
    
    
    
    DesiredBehavior:
    
    No crash.
    
    
    
    Patch:
    
    *** tcl8.3.2/generic/tclCmdMZ.c Mon Apr 10 17:08:26 2000
    
    --- tcl8.3.2-patch/generic/tclCmdMZ.c   Thu Aug 24 21:03:51 2000
    
    ***************
    
    *** 2626,2633 ****
    
                                    TraceVarProc, clientData);
    
                            if (tvarPtr->errMsg != NULL) {
    
                                ckfree(tvarPtr->errMsg);
    
                            }
    
    !                       ckfree((char *) tvarPtr);
    
                            break;
    
                        }
    
                    }
    
    --- 2626,2634 ----
    
                                    TraceVarProc, clientData);
    
                            if (tvarPtr->errMsg != NULL) {
    
                                ckfree(tvarPtr->errMsg);
    
    +                           tvarPtr->errMsg = NULL;
    
                            }
    
    !                       Tcl_EventuallyFree((ClientData) tvarPtr, TCL_DYNAMIC);
    
                            break;
    
                        }
    
                    }
    
    ***************
    
    *** 2729,2734 ****
    
    --- 2730,2745 ----
    
          int code;
    
          Tcl_DString cmd;
    
      
    
    +     /* 
    
    +      * We might call Tcl_Eval() below, and that might evaluate
    
    +      * [trace vdelete] which might try to free tvarPtr.  We want
    
    +      * to use tvarPtr until the end of this function, so we use
    
    +      * Tcl_Preserve() and Tcl_Release() to be sure it is not 
    
    +      * freed while we still need it.
    
    +      */
    
    + 
    
    +     Tcl_Preserve((ClientData) tvarPtr);
    
    + 
    
          result = NULL;
    
          if (tvarPtr->errMsg != NULL) {
    
            ckfree(tvarPtr->errMsg);
    
    ***************
    
    *** 2784,2792 ****
    
            result = NULL;
    
            if (tvarPtr->errMsg != NULL) {
    
                ckfree(tvarPtr->errMsg);
    
            }
    
    !       ckfree((char *) tvarPtr);
    
          }
    
          return result;
    
      }
    
      ^L
    
    --- 2795,2810 ----
    
            result = NULL;
    
            if (tvarPtr->errMsg != NULL) {
    
                ckfree(tvarPtr->errMsg);
    
    +           tvarPtr->errMsg = NULL;
    
            }
    
    !       Tcl_EventuallyFree((ClientData) tvarPtr, TCL_DYNAMIC);
    
          }
    
    + 
    
    +     /*
    
    +      * Match for Tcl_Preserve() near start of this function.
    
    +      */
    
    + 
    
    +     Tcl_Release((ClientData) tvarPtr);
    
          return result;
    
      }
    
      ^L
    
    
    
    PatchFiles:
    
    tclCmdMZ.c
    
    
    
    
    
    
    
  4. foundin changed to: "obsolete: 8.3.2"
  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: "15. Dict Object"
  10. title changed to: "[trace] should use Tcl_Preserve()"
  11. type changed to: "Support"