| Ticket UUID: | 069c9e43c443f3310098b923aa827c89c85281b1 | |||
| Title: | FreeOptionInternalRep() breaks Tk_CreateOptionTable() | |||
| Type: | Bug | Version: | 8.6.0 | |
| Submitter: | anonymous | Created on: | 2013-07-14 15:38:34 | |
| Subsystem: | 23. Option Parsing | Assigned To: | jan.nijtmans | |
| Priority: | 5 Medium | Severity: | Critical | |
| Status: | Closed | Last Modified: | 2013-08-14 13:16:54 | |
| Resolution: | Fixed | Closed By: | jan.nijtmans | |
| Closed on: | 2013-08-14 13:16:54 | |||
| Description: |
I have discovered an error that is causing a crash in xcircuit (see opencircuitdesign.com) when used with Tk version 8.6.0. This bug has been seen in several OS versions (Fedora, Arch Linux, Mac OS X).
This bug can be seen by compiling xcircuit with Tcl/Tk support and linking to Tcl/Tk version 8.6.0.
Error happens when xcircuit runs the script "wrapper.tcl". Here's what I see:
(1) The first call to "frame" (wrapper.tcl line 793, "frame .filelist.listwin") calls Tk_CreateOptionTable and returns an allocated memory value for optionSpecs[type] where type is TYPE_FRAME.
(2) Subsequent calls to "frame" get this same value back from Tk_CreateOptionTable, as they should
(3) A call to "checkbutton" a handful of lines later (wrapper.tcl, line 815, "checkbutton .filelist.textent.title.filter -bg beige ..." makes a call to ConfigureButton --> Tk_SetOptions --> GetOptionFromObj --> FreeOptionInternalRep. In FreeOptionInternalRep(), objPtr is a pointer to the Tcl_Obj object for the checkbutton option "-bg". Its internalRep is (apparently) a 2-pointer value, where ptr1 is the same value as that returned by Tk_CreateOptionTable for type TYPE_FRAME.
(4) FreeOptionInternalRep decrements refCount2 on this OptionTable pointer, finds that it is zero, and then calls ckfree() on this value. Note that at this point, refCount = 4 ("frame" has been called 4 times).
(5) Some time later, ckalloc() is called and repurposes the memory location for another subroutine. The memory location is overwritten with other data.
(6) "frame" is called again later (wrapper.tcl line 855, "frame .output.title -bg beige"). Again, at tkFrame.c line 483, Tk_CreateOptionTable is called for type TYPE_FRAME, and returns the original memory pointer, which has since been freed, reallocated, and overwritten with other data. Consequently, the program crashes.
It seems to me that the error is in FreeOptionInternalRep, where it is freeing the table pointer based on refCount2 while refCount still shows multiple references to the table. Maybe there is supposed to be an additional check for refCount > 0?
| |||
| User Comments: |
jan.nijtmans added on 2013-08-14 13:16:54:
Fixed in trunk [aaf11bdce2] jan.nijtmans added on 2013-08-01 09:34:58: Fully working now in [9aa08cb32d]. The only think holding me back merging it to trunk is: Is it really OK to share OptionTable's per thread in stead of per interpreter? Anyone who can deliver a test-case showing this is wrong? The effect of this change is that deleting an interpreter no longer means that the OptionTables created by that interpreter will be deleted immediately. That will only happen after calling Tcl_DeleteOptionTable() as soon as all Tcl_Obj's holding a reference to the option table are cleaned up. jan.nijtmans added on 2013-07-31 12:35:39: Something still wrong in Tk_DeleteOptionTable. Investigating ..... jan.nijtmans added on 2013-07-31 11:55:24: Suggested fix in [7ece6c712b]. Please evaluate. - In stead of two refcount's, there is only one now which is the sum of the number of times Tk_CreateOptionTable() is called and the number of Tcl_Obj's holding a reference to it. - Option tables are now shared for each thread, no longer for each interpreter. This was necessary because Tk_DeleteOptionTable() does not have an interp parameter. - The Optiontable is no longer deleted when the interpreter is gone, but it is removed when Tk_DeleteOptionTable() is called and there are no Tcl_Obj's holding references to it any more. This affects two testcases, because the reference-counting is very different now. jan.nijtmans added on 2013-07-14 17:03:25: See also Bug [2492179] and Commit [1b6f84f687] | |||
Home
Timeline
Branches
Tags
Forum
Tickets
Download
Wiki