Skip to content
Tcl Source Code History Of Ticket 24d7f1a6
Login

History Of Ticket 24d7f1a6

Artifacts Associated With Ticket 24d7f1a6

  1. Ticket change [b9f3f99358] (rid 249138) by teclab on 2025-12-06 22:56:14:

    1. assignee initialized to: "nobody"
    2. closer initialized to: "nobody"
    3. cmimetype initialized to: "text/x-markdown"
    4. comment initialized to:
      Dear TCL Team,
      
      might be an artifial problem, but this code below makes TCL crash:
      
      
      ```
      namespace eval rpc {
          namespace ensemble create -parameters name
          namespace export create
      
          proc create {name args} {
              variable _unique
              if {$name == "#auto"} {set name "rpc[incr _unique]"}
              namespace eval ::$name {
                  namespace ensemble create
                  namespace export init
                  trace add command [namespace current] delete [namespace current]::delete
                  proc init args {puts doneinit}
                  proc delete {oldName newName op} {
                      puts cleanup
                      namespace delete [namespace current]
                  }
              }
              ::${name}::init {*}$args
              return $name
          }
      }
      ```
      
      
      That's how you call it:
      
      `rpc r create`
      
      Now a second time:
      
      `rpc r create`
      
      *boom*
      
      
      Thank You!
      
    5. foundin initialized to: "core-8-6-branch"
    6. is_private initialized to: "0"
    7. login: "teclab"
    8. priority initialized to: "5 Medium"
    9. private_contact initialized to: "6bac77948ef91492d41f70b5be732fdb60f91282"
    10. resolution initialized to: "None"
    11. severity initialized to: "Minor"
    12. status initialized to: "Open"
    13. submitter initialized to: "teclab"
    14. subsystem initialized to: "21. [namespace]"
    15. title initialized to: "Recursive [namespace delete] causes a segfault"
    16. type initialized to: "Bug"
  2. Ticket change [63c150cef7] (rid 249144) by pointsman on 2025-12-07 15:04:17:

    1. icomment:
      Confirmed and confirmed for 9.0.1 also. The stack trace with 9.0.1 (as reported by valgrind) is:
      
      Invalid read of size 8
         at 0x489B624: TclCreateObjCommandInNs (tclBasic.c:2861)
         by 0x48A4457: TclNRCreateCommandInNs (tclBasic.c:8668)
         by 0x49F1320: Tcl_ProcObjCmd (tclProc.c:214)
         by 0x4897943: procObjCmd (tclBasic.c:308)
         by 0x489DBFB: Dispatch (tclBasic.c:4640)
         by 0x489DC5F: TclNRRunCallbacks (tclBasic.c:4656)
         by 0x489D510: Tcl_EvalObjv (tclBasic.c:4395)
         by 0x489FC98: TclEvalEx (tclBasic.c:5495)
         by 0x49C0D2E: Tcl_FSEvalFileEx (tclIOUtil.c:1793)
         by 0x49D23D1: Tcl_MainEx (tclMain.c:404)
         by 0x1091D3: main (tclAppInit.c:94)
       Address 0x110 is not stack'd, malloc'd or (recently) free'd
      
      
      Process terminating with default action of signal 11 (SIGSEGV)
       Access not within mapped region at address 0x110
         at 0x489B624: TclCreateObjCommandInNs (tclBasic.c:2861)
         by 0x48A4457: TclNRCreateCommandInNs (tclBasic.c:8668)
         by 0x49F1320: Tcl_ProcObjCmd (tclProc.c:214)
         by 0x4897943: procObjCmd (tclBasic.c:308)
         by 0x489DBFB: Dispatch (tclBasic.c:4640)
         by 0x489DC5F: TclNRRunCallbacks (tclBasic.c:4656)
         by 0x489D510: Tcl_EvalObjv (tclBasic.c:4395)
         by 0x489FC98: TclEvalEx (tclBasic.c:5495)
         by 0x49C0D2E: Tcl_FSEvalFileEx (tclIOUtil.c:1793)
         by 0x49D23D1: Tcl_MainEx (tclMain.c:404)
         by 0x1091D3: main (tclAppInit.c:94)
      
    2. login: "pointsman"
    3. mimetype: "text/plain"
  3. Ticket change [8bfac5a59a] (rid 249146) by chw on 2025-12-07 19:48:02:

    1. icomment:
      What about this patch?
      
      ---snip---
      Index: generic/tclNamesp.c
      ==================================================================
      --- generic/tclNamesp.c
      +++ generic/tclNamesp.c
      @@ -2538,14 +2538,21 @@
       TclEnsureNamespace(
           Tcl_Interp *interp,
           Tcl_Namespace *namespacePtr)
       {
           Namespace *nsPtr = (Namespace *) namespacePtr;
      +    Tcl_Namespace *newNsPtr;
      +
           if (!(nsPtr->flags & NS_DYING)) {
      -	return namespacePtr;
      +    	return namespacePtr;
           }
      -    return Tcl_CreateNamespace(interp, nsPtr->fullName, NULL, NULL);
      +    newNsPtr = Tcl_CreateNamespace(interp, nsPtr->fullName, NULL, NULL);
      +    if (newNsPtr == NULL) {
      +    	nsPtr->flags &= ~(NS_DYING|NS_KILLED);
      +	newNsPtr = (Tcl_Namespace *) nsPtr;
      +    }
      +    return newNsPtr;
       }
       
      
       /*
        *----------------------------------------------------------------------
        *
      
      ---snip---
      
    2. login: "chw"
    3. mimetype: "text/plain"
  4. Ticket change [bf8f866513] (rid 249298) by jan.nijtmans on 2025-12-08 10:58:31:

    1. assignee changed to: "jan.nijtmans"
    2. icomment:
      Put in a [655eb6343f1c353f|branch] now. Please test (everyone who want/can). On first sight, it looks good to me.
      
      Thanks!
      
    3. login: "jan.nijtmans"
    4. mimetype: "text/x-fossil-wiki"
  5. Ticket change [bea283fd4d] (rid 249385) by chw on 2025-12-10 04:57:31:

    1. icomment:
      More and more my impression is that TclEnsureNamespace() introduced this
      regression. Despite its name this function does not ensure that the
      given namespace is kept, since in case it got the NS_DYING flag it
      usually cannot be recreated, and the function ends up with returning NULL,
      i.e. no namespace at all.
      
      Given that TclEnsureNamespace()'s sole call site is in tclBasic.c IMO
      this function should be ditched once and for good.
      
    2. login: "chw"
    3. mimetype: "text/x-fossil-plain"
  6. Ticket change [d4cc0cccfd] (rid 249386) by chw on 2025-12-10 05:37:02:

    1. icomment:
      Please forget my last comment, it would re-introduce the
      test failure in basic-15.2 which got fixed by TclEnsureNamespace()
      according to ticket [0e4d88b6502ac8fe0ccc912c2bd2ef4c16279837].
      
      Sorry for the noise!
      
    2. login: "chw"
    3. mimetype: "text/x-fossil-plain"
  7. Ticket change [4565b9d8ec] (rid 252911) by apnadkarni on 2026-04-20 16:54:24:

    1. icomment:
      A simpler illustration of the same issue, just to reduce the noise
      
      ```
       namespace eval ns {proc p {} {}; proc q {} {}; namespace delete [namespace current]; proc p {} {}; proc q {} {}}
      ```
      
      Before even attempting a fix, I'm not clear on what the semantics should be when (a) a namespace is deleted in the middle of its execution and (b) when it is recreated from within its own eval.
      
    2. login: "apnadkarni"
    3. mimetype: "text/x-markdown"
  8. Ticket change [ab0b303e73] (rid 252941) by apnadkarni on 2026-04-21 11:53:06:

    1. icomment:
      Proposed fix in [bug-24d7f1a6-apn](https://core.tcl-lang.org/tcl/info/0611b06f32436e3a). Passes test and valgrind.
      
      Note the fix results in the namespace being recreated after deletion. I am not entirely sure that is the desirable behavior but that is how the current (non-crashing) test cases behave so I have preserved that.
      
    2. login: "apnadkarni"
    3. mimetype: "text/x-markdown"
  9. Ticket change [f393438790] (rid 252981) by apnadkarni on 2026-04-22 11:12:00:

    1. closedate changed to: "2461152.966673831"
    2. closer changed to: "apnadkarni"
    3. icomment: "Fixed for 8.6, 9.0 and 9.1."
    4. login: "apnadkarni"
    5. mimetype: "text/plain"
    6. resolution changed to: "Fixed"
    7. status changed to: "Closed"
  10. Ticket change [b9cd545907] (rid 252985) by dgp on 2026-04-22 16:09:00:

    1. closedate changed to: "2461153.17292397"
    2. closer changed to: "dgp"
    3. icomment:
      Namespace lifetime management has been fertile ground for crashes and bugs.
      It is hard to get right, and often hard to even define what "right" is.
      
      For whatever benefit it may bring to future developers, this particular
      segfault originates in checkin [4039b2b895].  Apply the patch to that
      checkin and it fixes the issue back then as well.
      
    4. login: "dgp"
    5. mimetype: "text/x-fossil-plain"