Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2007-09-11
06:06 • Closed ticket [1740631fff]: Memory corruption in Tcl_UpdateLinkedVar plus 7 ... artifact: e087812afd user: hobbs
2007-07-17
02:59 • Ticket [1740631fff]: 4 changes artifact: 99da1ed6ae user: emaros
2007-06-21
17:48 • Ticket [1740631fff]: 1 change artifact: fc7af5e039 user: dkf
2007-06-20
23:22 • New ticket [1740631fff]. artifact: 254ed32d79 user: nobody

Memory corruption in Tcl_UpdateLinkedVar

Closed / Fixed1740631fffffffffffffffffffffffffffffffffCreated 19 years agoUpdated 19 years ago
Descriptionplain2007-06-20 23:22:43
Solaris 10 on sparc

Calling Tcl_UnlinkVar in a callback that is invoked by Tcl_UpdateLinkedVar causes memory corruption because linkPtr is used after it has been freed.

Here is a patch to fix the problem by making a second call to Tcl_VarTraceInfo.

--- tcl8.4.15/generic/tclLink.c       2007-05-10 11:23:58.000000000 -0700
+++ tcl8.4.15-new/generic/tclLink.c   2007-06-20 14:19:24.792783000 -0700
@@ -206,6 +206,12 @@
     Tcl_IncrRefCount(objPtr);
     Tcl_ObjSetVar2(interp, linkPtr->varName, NULL, objPtr, TCL_GLOBAL_ONLY);
     Tcl_DecrRefCount(objPtr);
+    /* Callback may have unlinked the variable */
+    linkPtr = (Link *) Tcl_VarTraceInfo(interp, varName, TCL_GLOBAL_ONLY,
+           LinkTraceProc, (ClientData) NULL);
+    if (linkPtr == NULL) {
+       return;
+    }
     linkPtr->flags = (linkPtr->flags & ~LINK_BEING_UPDATED) | savedFlag;
 }
dkf Ticket [1740631fff]: 1 change [History diff]2007-06-21 17:48:35
emarosplain2007-07-17 02:59:08
Logged In: YES 
user_id=334297
Originator: NO

This patch has allowed our application to run continuously for several weeks where before we would have aborts once a day.
hobbsplain2007-09-11 06:06:42
Logged In: YES 
user_id=72656
Originator: NO

In 8.4.16 and 8.5b1.
Log in (anonymous is fine) to add a comment.