Skip to content
Tcl Source Code History Of Ticket 70944d8f141bfe84
Login

History Of Ticket 70944d8f141bfe84

Artifacts Associated With Ticket 70944d8f141bfe84

  1. Ticket change [7e07975e64] (rid 187134) by ivk on 2020-09-28 13:28:16:

    1. assignee initialized to: "nobody"
    2. closer initialized to: "nobody"
    3. cmimetype initialized to: "text/plain"
    4. comment initialized to:
      We have multiple TCL interpreters running in different threads. We are suffering from a crash that seems to be caused by the access to the already deleted ItclClass. Long story short, itcl tries to delete the same class twice - when another thread interferes, it can allocate a new class at the same address overriding the ITCL_CLASS_IS_FREED flag which leads to a crash when itcl access this object for the second time.
      Consider the following snippet (crash.tcl):
      
      package require Iwidgets
      iwidgets::Labeledwidget  .l
      pack .l
      after 1000
      exit
      
      I ran it like this (using the self-built interpreter to remove our multi-threaded environment from investigation): 
      TCL_FINALIZE_ON_EXIT=1 tclsh8.6 ~/scripts/crash.tcl
      
      I've also added some logging to ItclReleaseClass():
      
      if (iclsPtr->refCount-- <= 1) {
          pthread_t id = pthread_self();
          fprintf(stderr, "    ItclReleaseClass: %p, refCount: %d, thread: %lu\n", iclsPtr, iclsPtr->refCount, id);
          ItclFreeClass((char *) clientData);
      }
      
      Now, in the logs I see:
          ItclReleaseClass: 0x6290004dba10, refCount: 0, thread: 140564963183552
          ItclReleaseClass: 0x6290004dba10, refCount: -1, thread: 140564963183552
      
      This refcount -1 looks very suspicious meaning that class has already been freed. In a single-threaded environment there are no (re)allocations at this point of time => flags are not overwritten => the code works. However, it doesn't seem right to access the freed memory (without the custom allocator, that would be a sigsegv, but TCL allocator helps here preventing segmentation violation).
      
    5. is_private initialized to: "0"
    6. login: "ivk"
    7. priority initialized to: "5 Medium"
    8. resolution initialized to: "None"
    9. severity initialized to: "Minor"
    10. status initialized to: "Open"
    11. submitter initialized to: "ivk"
    12. subsystem initialized to: "69. Other"
    13. title initialized to: "invalid refcount for classes in itcl?"
    14. type initialized to: "Bug"
  2. Ticket change [48332ed9ac] (rid 187136) by dgp on 2020-09-28 13:38:21:

    1. icomment:
      
      Please report precise versions of all packages in use.
      
    2. login: "dgp"
    3. mimetype: "text/plain"
  3. Ticket change [9e7383f8ad] (rid 187137) by ivk on 2020-09-28 14:01:52:

    1. foundin changed to: "tcl 8.6.10, itcl 4.2.0"
    2. login: "ivk"
    3. mimetype: "text/plain"
  4. Ticket change [93bbe817e4] (rid 187144) by dgp on 2020-09-28 14:18:28:

    1. icomment:
      
      Can the problem be demonstrated without use of Itk and Iwidgets?
      
    2. login: "dgp"
    3. mimetype: "text/plain"
  5. Ticket change [23709346db] (rid 187154) by ivk on 2020-09-28 14:45:02:

    1. icomment:
      > Can the problem be demonstrated without use of Itk and Iwidgets?
      
      Not that I am aware of - this is already a reduced example, original script is several thousands lines of code.
      I have debugged the itcl code to what I think is the problem - e.g. the refcounting issue. It appears that the number of pointers to the class does not match the actual reference count, but my knowledge of tcl code is very poor and I cannot fix that myself.
      
    2. login: "ivk"
    3. mimetype: "text/plain"
  6. Ticket change [6b7708a560] (rid 187349) by ivk on 2020-10-01 09:15:31:

    1. icomment:
      I do see the same output with the simple hello world:
      
      package require Itcl
      itcl::class helloworld {
        public variable owner "No-one"
      
        method greet {} { puts "Hello World from $owner" }
      }
      
      helloworld  h1
      h1 greet
      
      This example doesn't crash in the multi-threaded environment, though.
      
    2. login: "ivk"
    3. mimetype: "text/plain"
  7. Ticket change [f082a3d464] (rid 187357) by sebres on 2020-10-02 13:16:47:

    1. closedate changed to: "2459125.05333207"
    2. closer changed to: "sebres"
    3. icomment:
      This is surely an Itcl issue, so I opened new ticket there - [../itcl/info/f0a72b44d72986a9|itcl/f0a72b44d7].
      
      Confirmed (and fixed there).
      
      Thus closed here.
      
    4. login: "sebres"
    5. mimetype: "text/x-fossil-wiki"
    6. status changed to: "Closed"