Index: generic/tclCmdMZ.c
===================================================================
RCS file: /cvsroot/tcl/tcl/generic/tclCmdMZ.c,v
retrieving revision 1.82.2.6
diff -u -r1.82.2.6 tclCmdMZ.c
--- generic/tclCmdMZ.c	16 Jul 2003 08:24:20 -0000	1.82.2.6
+++ generic/tclCmdMZ.c	24 Sep 2003 02:08:33 -0000
@@ -3350,6 +3350,7 @@
 	    resultListPtr = Tcl_NewListObj(0, (Tcl_Obj **) NULL);
 	    while ((clientData = Tcl_CommandTraceInfo(interp, name, 0,
 		    TraceCommandProc, clientData)) != NULL) {
+		int numOps = 0;
 
 		TraceCommandInfo *tcmdPtr = (TraceCommandInfo *) clientData;
 
@@ -3363,6 +3364,7 @@
 		 */
 
 		elemObjPtr = Tcl_NewListObj(0, (Tcl_Obj **) NULL);
+		Tcl_IncrRefCount(elemObjPtr);
 		if (tcmdPtr->flags & TCL_TRACE_ENTER_EXEC) {
 		    Tcl_ListObjAppendElement(NULL, elemObjPtr,
 			    Tcl_NewStringObj("enter",5));
@@ -3379,7 +3381,13 @@
 		    Tcl_ListObjAppendElement(NULL, elemObjPtr,
 			    Tcl_NewStringObj("leavestep",9));
 		}
+		Tcl_ListObjLength(NULL, elemObjPtr, &numOps);
+		if (0 == numOps) {
+		    Tcl_DecrRefCount(elemObjPtr);
+                    continue;
+                }
 		Tcl_ListObjAppendElement(NULL, eachTraceObjPtr, elemObjPtr);
+		Tcl_DecrRefCount(elemObjPtr);
 		elemObjPtr = NULL;
 		
 		Tcl_ListObjAppendElement(NULL, eachTraceObjPtr, 
@@ -3545,6 +3553,7 @@
 	    resultListPtr = Tcl_NewListObj(0, (Tcl_Obj **) NULL);
 	    while ((clientData = Tcl_CommandTraceInfo(interp, name, 0,
 		    TraceCommandProc, clientData)) != NULL) {
+		int numOps = 0;
 
 		TraceCommandInfo *tcmdPtr = (TraceCommandInfo *) clientData;
 
@@ -3558,6 +3567,7 @@
 		 */
 
 		elemObjPtr = Tcl_NewListObj(0, (Tcl_Obj **) NULL);
+		Tcl_IncrRefCount(elemObjPtr);
 		if (tcmdPtr->flags & TCL_TRACE_RENAME) {
 		    Tcl_ListObjAppendElement(NULL, elemObjPtr,
 			    Tcl_NewStringObj("rename",6));
@@ -3566,7 +3576,13 @@
 		    Tcl_ListObjAppendElement(NULL, elemObjPtr,
 			    Tcl_NewStringObj("delete",6));
 		}
+		Tcl_ListObjLength(NULL, elemObjPtr, &numOps);
+		if (0 == numOps) {
+		    Tcl_DecrRefCount(elemObjPtr);
+                    continue;
+                }
 		Tcl_ListObjAppendElement(NULL, eachTraceObjPtr, elemObjPtr);
+		Tcl_DecrRefCount(elemObjPtr);
 
 		elemObjPtr = Tcl_NewStringObj(tcmdPtr->command, -1);
 		Tcl_ListObjAppendElement(NULL, eachTraceObjPtr, elemObjPtr);
Index: tests/trace.test
===================================================================
RCS file: /cvsroot/tcl/tcl/tests/trace.test,v
retrieving revision 1.26.2.1
diff -u -r1.26.2.1 trace.test
--- tests/trace.test	27 Mar 2003 13:11:17 -0000	1.26.2.1
+++ tests/trace.test	24 Sep 2003 02:08:34 -0000
@@ -2093,6 +2093,42 @@
     list [catch {trace remove execution} res] $res
 } {1 {wrong # args: should be "trace remove execution name opList command"}}
 
+# Missing test number to keep in sync with the 8.5 branch
+# (want to backport those tests?)
+
+test trace-31.1 {command and execution traces shared struct} {
+    # Tcl Bug 807243
+    proc foo {} {}
+    trace add command foo delete foo
+    trace add execution foo enter foo
+    set result [trace info command foo]
+    trace remove command foo delete foo
+    trace remove execution foo enter foo
+    rename foo {}
+    set result
+} [list [list delete foo]]
+test trace-31.2 {command and execution traces shared struct} {
+    # Tcl Bug 807243
+    proc foo {} {}
+    trace add command foo delete foo
+    trace add execution foo enter foo
+    set result [trace info execution foo]
+    trace remove command foo delete foo
+    trace remove execution foo enter foo
+    rename foo {}
+    set result
+} [list [list enter foo]]
+
+test trace-32.1 {mystery memory corruption} knownBug {
+    # Tcl Bug 811483
+    proc foo {} {}
+    trace add command foo delete foo
+    trace add execution foo enter foo
+    set result [trace info command foo]
+    rename foo {}
+    set result
+} [list [list delete foo]]
+
 # Delete procedures when done, so we don't clash with other tests
 # (e.g. foobar will clash with 'unknown' tests).
 catch {rename foobar {}}
