Tcl Source Code

Artifact [cf8f3427f3]
Login

Artifact cf8f3427f36d8bc4a23d3567896fd9d09c69a2ad:

Attachment "trace.patch" to ticket [402501ffff] added by dgp 2001-08-23 22:53:10.
Index: generic/tclCmdMZ.c
===================================================================
RCS file: /cvsroot/tcl/tcl/generic/tclCmdMZ.c,v
retrieving revision 1.43
diff -u -r1.43 tclCmdMZ.c
--- generic/tclCmdMZ.c	2001/08/07 00:56:15	1.43
+++ generic/tclCmdMZ.c	2001/08/23 15:51:09
@@ -2857,8 +2857,9 @@
 			    TraceVarProc, clientData);
 		    if (tvarPtr->errMsg != NULL) {
 			ckfree(tvarPtr->errMsg);
+			tvarPtr->errMsg = NULL;
 		    }
-		    ckfree((char *) tvarPtr);
+		    Tcl_EventuallyFree((ClientData) tvarPtr, TCL_DYNAMIC);
 		    break;
 		}
 	    }
@@ -3593,6 +3594,16 @@
     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);
@@ -3665,9 +3676,16 @@
 	result = NULL;
 	if (tvarPtr->errMsg != NULL) {
 	    ckfree(tvarPtr->errMsg);
+	    tvarPtr->errMsg = NULL:
 	}
-	ckfree((char *) tvarPtr);
+	Tcl_EventuallyFree((ClientData) tvarPtr, TCL_DYNAMIC);
     }
+
+    /*
+     * Match for Tcl_Preserve() near start of this function.
+     */
+
+    Tcl_Release((ClientData) tvarPtr);
     return result;
 }