summaryrefslogtreecommitdiffstats
path: root/generic/tclOOMethod.c
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2011-03-05 00:35:57 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2011-03-05 00:35:57 (GMT)
commit6f1fd26e91b778b8d1e972e425c2e2593a41f92d (patch)
treedc5e2c9a6260b924b0812e00d961eb79fe9fe786 /generic/tclOOMethod.c
parent17bf2e2c7ac19e4a2d576a88d3bec1413a02be74 (diff)
parent80a9e493176e81c6becbb1715367300d20208449 (diff)
downloadtcl-6f1fd26e91b778b8d1e972e425c2e2593a41f92d.zip
tcl-6f1fd26e91b778b8d1e972e425c2e2593a41f92d.tar.gz
tcl-6f1fd26e91b778b8d1e972e425c2e2593a41f92d.tar.bz2
[Bug 3185009]: Keep references to resolved object variables so that an unset doesn't leave any dangling pointers for code to trip over.
Diffstat (limited to 'generic/tclOOMethod.c')
-rw-r--r--generic/tclOOMethod.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/generic/tclOOMethod.c b/generic/tclOOMethod.c
index 44eb083..4f29337 100644
--- a/generic/tclOOMethod.c
+++ b/generic/tclOOMethod.c
@@ -1055,6 +1055,14 @@ ProcedureMethodCompiledVarConnect(
}
if (cacheIt) {
infoPtr->cachedObjectVar = TclVarHashGetValue(hPtr);
+
+ /*
+ * We must keep a reference to the variable so everything will
+ * continue to work correctly even if it is unset; being unset does
+ * not end the life of the variable at this level. [Bug 3185009]
+ */
+
+ VarHashRefCount(infoPtr->cachedObjectVar)++;
}
return TclVarHashGetValue(hPtr);
}
@@ -1065,6 +1073,14 @@ ProcedureMethodCompiledVarDelete(
{
OOResVarInfo *infoPtr = (OOResVarInfo *) rPtr;
+ /*
+ * Release the reference to the variable if we were holding it.
+ */
+
+ if (infoPtr->cachedObjectVar) {
+ VarHashRefCount(infoPtr->cachedObjectVar)--;
+ TclCleanupVar((Var *) infoPtr->cachedObjectVar, NULL);
+ }
Tcl_DecrRefCount(infoPtr->variableObj);
ckfree((char *) infoPtr);
}