|
2026-11-01
| ||
| 20:37 | • Closed ticket [28de60cef5]: Segfault in destructor using tsv::lock plus 7 ot... artifact: 56956b0708 user: dkf | |
| 20:36 | Fix [28de60cef5] and [b4637c4312] check-in: f3f08274f7 user: dkf tags: trunk, main | |
| 20:30 | Fix [28de60cef5] and [b4637c4312] check-in: 298d1d97d5 user: dkf tags: core-9-0-branch | |
| 17:57 | Backport of Fix [28de60cef5]: reading an object variable from code compiled at run time (e.g. [eval]... check-in: db7f34af59 user: dkf tags: oo-destructor-deleted-namespace-90 | |
|
2026-10-13
| ||
| 19:08 | • Ticket [b4637c4312] upvar segfault for destroyed object status still Open wi... artifact: 42f3dc584f user: serhiy.storchaka | |
| 19:06 | Fix [b4637c4312]: [upvar] to an object variable after the object was destroyed in its method crashed... closed check-in: de6527681f user: serhiy.storchaka tags: oo-destructor-deleted-namespace | |
| 15:27 | • Ticket [28de60cef5] Segfault in destructor using tsv::lock status still Open... artifact: 42d6509f0a user: serhiy.storchaka | |
| 15:25 | Fix [28de60cef5]: reading an object variable from code compiled at run time (e.g. [eval]) in a destr... check-in: f38a74a978 user: serhiy.storchaka tags: oo-destructor-deleted-namespace | |
|
2020-02-16
| ||
| 10:44 | • New ticket [28de60cef5] Segfault in destructor using tsv::lock. artifact: d76b6e5673 user: cyan | |
Segfault in destructor using tsv::lock
Closed / Fixed28de60cef5133f1bd5c07dadf4d1a6e1989878c4Created 7 years agoUpdated 31 days ago
Descriptionplain2020-02-16 10:44:05
I'm not sure this is the right place for this (maybe Thread?), but I've hit a
segfault that involves the timing of an object's namespace deletion. I'm
filing it against TclOO because I've hit a similar issue with a destructor
implemented in c that doesn't involve tsv::lock, but the this version uses only
Tcl script and standard packages distributed with Tcl releases:
package require Thread
oo::class create foo {
variable thing
constructor {} {
set thing something
}
destructor {
set local $thing
rename [self] {}
tsv::lock foo {
puts "local: $local" ;# works
puts "thing: $thing" ;# segfault
}
}
}
[foo new] destroy
I admit that "rename [self] {}" in the destructor is silly, but it works if the
tsv::lock isn't involved, and it's there to simulate the situation that occurs
in the real code where I found this problem, where it is less silly.
The crash happens on a call to
Tcl_CreateHashEntry(TclVarTable(contextPtr->oPtr->namespacePtr) in
ProcedureMethodCompiledVarConnect where contextPtr->oPtr->namespacePtr is NULL.
In the possibly related case with a C method and destructor, the C method does
a Tcl_DeleteCommandFromToken(interp, thisObjectCommand) on itself for the side
effect of destroying the instance (if a more direct way of doing this exists
please point me to it). Sometimes this does the expected thing and calls the
destructor before returning from the Tcl_DeleteCommandFromToken, but under
other circumstances (haven't found the relevant trigger yet, maybe NR context?)
it chains to the destructor after the c method that called
Tcl_DeleteCommandFromToken returns. But in that case (without calling the
destructor yet) all the object metadata has been removed and the namespace
deleted when Tcl_DeleteCommandFromToken returns, causing some difficulties for
the destructor when it runs later.
Referenced by6
f3f08274f7Fix [28de60cef5] and [b4637c4312] check-in2026-11-01 20:36:04298d1d97d5Fix [28de60cef5] and [b4637c4312] check-in2026-11-01 20:30:55db7f34af59Backport of Fix [28de60cef5]: reading an object variable from code compiled at run time (e.g. [eval]) in a destructor... check-in2026-11-01 17:57:2042f3dc584fTicket [b4637c4312] upvar segfault for destroyed object status still Open with 4 other changes ticket2026-10-13 19:08:05de6527681fFix [b4637c4312]: [upvar] to an object variable after the object was destroyed in its method crashed. Same cause as [28de60cef5]; add a test. check-in2026-10-13 19:06:40f38a74a978Fix [28de60cef5]: reading an object variable from code compiled at run time (e.g. [eval]) in a destructor, after the object was renamed to {}, crashed: the namespace of the object was already deleted. Do not resolve object variables then. check-in2026-10-13 15:25:09
serhiy.storchakawiki2026-10-13 15:27:14
Still crashes with 8.6.17, 9.0 and 9.1. It does not need Thread:
eval or uplevel 0 instead of
tsv::lock crash the same way. rename [self] {} deletes
the namespace of the object, and the variable resolver of TclOO then looks up
the variable in the deleted namespace.
Proposed fix in branch oo-destructor-deleted-namespace: do not resolve object variables when the namespace is already deleted; reading such a variable is then an error. Test oo-3.13.
dkfmarkdown2026-11-01 20:37:55
It was a missing NULL check. Ought to be fixed now (9.0 onwards).
Log in (anonymous is fine) to add a comment.