Artifacts Associated With Ticket 70944d8f141bfe84
Ticket change [7e07975e64] (rid 187134) by ivk on 2020-09-28 13:28:16:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/plain"
- 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). - is_private initialized to: "0"
- login: "ivk"
- priority initialized to: "5 Medium"
- resolution initialized to: "None"
- severity initialized to: "Minor"
- status initialized to: "Open"
- submitter initialized to: "ivk"
- subsystem initialized to: "69. Other"
- title initialized to: "invalid refcount for classes in itcl?"
- type initialized to: "Bug"
Ticket change [48332ed9ac] (rid 187136) by dgp on 2020-09-28 13:38:21:
- icomment:
Please report precise versions of all packages in use.
- login: "dgp"
- mimetype: "text/plain"
- icomment:
Ticket change [9e7383f8ad] (rid 187137) by ivk on 2020-09-28 14:01:52:
- foundin changed to: "tcl 8.6.10, itcl 4.2.0"
- login: "ivk"
- mimetype: "text/plain"
Ticket change [93bbe817e4] (rid 187144) by dgp on 2020-09-28 14:18:28:
- icomment:
Can the problem be demonstrated without use of Itk and Iwidgets?
- login: "dgp"
- mimetype: "text/plain"
- icomment:
Ticket change [23709346db] (rid 187154) by ivk on 2020-09-28 14:45:02:
- 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.
- login: "ivk"
- mimetype: "text/plain"
- icomment:
Ticket change [6b7708a560] (rid 187349) by ivk on 2020-10-01 09:15:31:
- 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. - login: "ivk"
- mimetype: "text/plain"
- icomment:
Ticket change [f082a3d464] (rid 187357) by sebres on 2020-10-02 13:16:47:
- closedate changed to: "2459125.05333207"
- closer changed to: "sebres"
- 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.
- login: "sebres"
- mimetype: "text/x-fossil-wiki"
- status changed to: "Closed"