Tcl Source Code

Check-in [0c05782b28]
Login
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2019 Conference, Houston/TX, US, Nov 4-8
Send your abstracts to [email protected]
or submit via the online form by Sep 9.

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:[Bug 3185009]: Keep references to resolved object variables so that an unset doesn't leave any dangling pointers for code to trip over.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | Bug 3185009
Files: files | file ages | folders
SHA1: 0c05782b28f1caa36564602437acf675dbcdb242
User & Date: dkf 2011-03-04 18:23:04
Original Comment: Keep references to resolved object variables so that an unset doesn't leave any dangling pointers for code to trip over.
Context
2011-03-05
00:35
[Bug 3185009]: Keep references to resolved object variables so that an unset doesn't leave any dangl... check-in: 6005a9d1b7 user: dkf tags: trunk
2011-03-04
18:23
[Bug 3185009]: Keep references to resolved object variables so that an unset doesn't leave any dangl... check-in: 0c05782b28 user: dkf tags: Bug 3185009
2011-03-01
20:02
fix leaks in throw and unset compilers check-in: 0e18b9441c user: mig tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to ChangeLog.








1
2
3
4
5
6
7






2011-03-01  Miguel Sofer  <[email protected]>

	* generic/tclCompCmdsSZ.c (TclCompileThrowCmd)
	(TclCompileUnsetCmd): fix leaks
	
	* generic/tclBasic.c:       This is [Patch 3168398],
	* generic/tclCompCmdsSZ.c:  Joe Mistachkin's optimisation
>
>
>
>
>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
2011-03-04  Donal K. Fellows  <[email protected]>

	* generic/tclOOMethod.c (ProcedureMethodCompiledVarConnect)
	(ProcedureMethodCompiledVarDelete): [Bug 3185009]: Keep references to
	resolved object variables so that an unset doesn't leave any dangling
	pointers for code to trip over.

2011-03-01  Miguel Sofer  <[email protected]>

	* generic/tclCompCmdsSZ.c (TclCompileThrowCmd)
	(TclCompileUnsetCmd): fix leaks
	
	* generic/tclBasic.c:       This is [Patch 3168398],
	* generic/tclCompCmdsSZ.c:  Joe Mistachkin's optimisation

Changes to generic/tclOOMethod.c.

1053
1054
1055
1056
1057
1058
1059








1060
1061
1062
1063
1064
1065
1066
1067
1068
1069








1070
1071
1072
1073
1074
1075
1076
    hPtr = Tcl_CreateHashEntry(TclVarTable(contextPtr->oPtr->namespacePtr),
	    (char *) variableObj, &isNew);
    if (isNew) {
	TclSetVarNamespaceVar((Var *) TclVarHashGetValue(hPtr));
    }
    if (cacheIt) {
	infoPtr->cachedObjectVar = TclVarHashGetValue(hPtr);








    }
    return TclVarHashGetValue(hPtr);
}

static void
ProcedureMethodCompiledVarDelete(
    Tcl_ResolvedVarInfo *rPtr)
{
    OOResVarInfo *infoPtr = (OOResVarInfo *) rPtr;









    Tcl_DecrRefCount(infoPtr->variableObj);
    ckfree((char *) infoPtr);
}

static int
ProcedureMethodCompiledVarResolver(
    Tcl_Interp *interp,






>
>
>
>
>
>
>
>










>
>
>
>
>
>
>
>







1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
    hPtr = Tcl_CreateHashEntry(TclVarTable(contextPtr->oPtr->namespacePtr),
	    (char *) variableObj, &isNew);
    if (isNew) {
	TclSetVarNamespaceVar((Var *) TclVarHashGetValue(hPtr));
    }
    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);
}

static void
ProcedureMethodCompiledVarDelete(
    Tcl_ResolvedVarInfo *rPtr)
{
    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);
}

static int
ProcedureMethodCompiledVarResolver(
    Tcl_Interp *interp,

Changes to tests/oo.test.

2576
2577
2578
2579
2580
2581
2582
















2583
2584
2585
2586
2587
2588
2589
	    set v 0
	}
    }
    leaktest {[foo new] destroy}
} -cleanup {
    foo destroy
} -result 0

















# A feature that's not supported because the mechanism may change without
# warning, but is supposed to work...
test oo-28.1 {scripted extensions to oo::define} -setup {
    interp create foo
    foo eval {oo::class create cls {export eval}}
} -cleanup {






>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
	    set v 0
	}
    }
    leaktest {[foo new] destroy}
} -cleanup {
    foo destroy
} -result 0
# This test will actually (normally) crash if it fails!
test oo-27.13 {variables declaration: Bug 3185009: require refcount management} -setup {
    oo::object create foo
} -body {
    oo::objdefine foo {
	variable x
	method set v {set x $v}
	method unset {} {unset x}
	method exists {} {info exists x}
	method get {} {return $x}
    }
    list [foo exists] [foo set 7] [foo exists] [foo get] [foo unset] \
	[foo exists] [catch {foo get} msg] $msg
} -cleanup {
    foo destroy
} -result {0 7 1 7 {} 0 1 {can't read "x": no such variable}}

# A feature that's not supported because the mechanism may change without
# warning, but is supposed to work...
test oo-28.1 {scripted extensions to oo::define} -setup {
    interp create foo
    foo eval {oo::class create cls {export eval}}
} -cleanup {