Skip to content
Tcl Source Code View Ticket
Login

View Ticket

upvar segfault for destroyed object

Closed / Fixedb4637c4312a59ca57ef8148623f973a7493e950aCreated 2 years agoUpdated 32 days ago
Descriptionplain2025-05-08 09:31:31
This script crashes tcl interpreter (segmentation fault on linux or silent crash on windows):
---
proc crash {varname} {
    upvar $varname V ;# <<<< crashes here !!!
}

oo::class create C {
    variable V
    method run {} {
        my destroy
        crash V
    }
}

C create c
c run
---

Trying on:
windows tcl 8.6.16, 9.0.2
linux tcl 8.6.12
https://onecompiler.com/tcl 8.6.14
Referenced by4
serhiy.storchakawiki2026-10-13 19:08:05

Same cause as [28de60cef5]: after [my destroy] the namespace of the object is deleted, and resolving V for upvar in the method looked it up there. It also crashes with 8.6.17, 9.0 and 9.1.

Proposed fix in branch oo-destructor-deleted-namespace: the script returns normally, and V is a new unset variable. Test oo-3.14.

dkfmarkdown2026-11-01 17:42:58

Confirming the crash with 9.1.0, and it looks like something that wants a backport fix to 9.0 too.

No plans to backport to 8.6, given the support status of that release line.

dkfmarkdown2026-11-01 20:38:45

Fix applied to 9.0 onwards.

dkfmarkdown2026-11-01 20:39:55

BTW, thanks for hunting this down, Serhiy.

Log in (anonymous is fine) to add a comment.