Overview
| Artifact ID: | 7e07975e6438f6b7bdeb3699efbc786e2b7dfbff4c1838b1eeafcc9069de8e7e |
|---|---|
| Ticket: | 70944d8f141bfe849c6bd37ded7ce04ce8e27052
invalid refcount for classes in itcl? |
| User & Date: | ivk on 2020-09-28 13:28:16 |
Changes
- assignee changed to: "nobody"
- closer changed to: "nobody"
- cmimetype changed to: "text/plain"
- comment changed 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). - is_private changed to: "0"
- login: "ivk"
- priority changed to: "5 Medium"
- resolution changed to: "None"
- severity changed to: "Minor"
- status changed to: "Open"
- submitter changed to: "ivk"
- subsystem changed to: "69. Other"
- title changed to: "invalid refcount for classes in itcl?"
- type changed to: "Bug"