Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 4262691a9ca5a7234710638d26d382d00d251f5b4a57d5b3ba98e9fd9de787cd
Ticket: 708422a066c634e914c10fdf21bac97f239d602f
unset traces enable calling an object command mid-destruction
User & Date: andy on 2024-09-04 04:13:52
Changes

  1. assignee changed to: "nobody"
  2. closer changed to: "nobody"
  3. cmimetype changed to: "text/x-markdown"
  4. comment changed to:
    unset traces can inject arbitrary code right in the middle of destroying an object.  In this halfway state, the object command exists, [info object isa object] says it's valid, but the object namespace is gone.  Deleting the object namespace is what triggers the unset trace.
    
    The following code dies with SIGSEGV inside TclOOGetCallContext (tclOOCall.c:1024) when it does `oPtr->selfCls->classChainCache != NULL` because `oPtr->selfCls` is NULL.
    
    ```
    oo::class create foo {
        variable x
        constructor {} {
            trace add variable x unset [list apply {{self ns args} {
                puts [list args -> $args]
                puts [list info object isa object $self -> [info object isa object $self]]
                puts [list namespace exists $ns -> [namespace exists $ns]]
                $self test
            }} [self] [self namespace]]
        }
        method test {} {}
    }
    [foo new] destroy
    ```
    
    The above prints:
    
    ```
    args -> {::oo::Obj12::x {} unset}
    info object isa object ::oo::Obj12 -> 1
    namespace exists ::oo::Obj12 -> 0
    Segmentation fault (core dumped)
    ```
    
    For now, my workaround is to check for namespace existence in my unset trace, allowing me to distinguish between variables being unset for normal reasons and variables being unset because the object is being destroyed.
    
  5. foundin changed to: "8.6.14"
  6. is_private changed to: "0"
  7. login: "andy"
  8. priority changed to: "5 Medium"
  9. private_contact changed to: "662c23482b0bf6a505f39e48fb7ad43af8dee4d3"
  10. resolution changed to: "None"
  11. severity changed to: "Severe"
  12. status changed to: "Open"
  13. submitter changed to: "andy"
  14. subsystem changed to: "35. TclOO Package"
  15. title changed to:
    unset traces enable calling a class method mid-destruction
    
  16. type changed to: "Bug"