| Ticket UUID: | b964b98d1b1fa9bc1abf08a09bcaef20c4ed0ba | |||
| Title: | ttk manager relayout use-after-free during teardown (Aqua) | |||
| Type: | Bug | Version: | 9.0.3/9.0.4 | |
| Submitter: | anonymous | Created on: | 2026-07-04 08:19:00 | |
| Subsystem: | (unused) | Assigned To: | nobody | |
| Priority: | 5 Medium | Severity: | Minor | |
| Status: | Open | Last Modified: | 2026-10-07 02:02:29 | |
| Resolution: | None | Closed By: | nobody | |
| Closed on: | ||||
| Description: |
On macOS/Aqua, destroying a nested Affected
Symptom / backtrace (lldb, unstripped build)
Mechanism
Teardown of a nested panedwindow destroys children (content) before the container. On Aqua,
Ruled out
Possible fix directionThe manager relayout must not run on content that is being torn down. Candidates:
Full disclosure: The report above was AI generated after a debug session. | |||
| User Comments: |
marc_culler (claiming to be Marc Culler) added on 2026-10-07 02:02:29:
Thanks! I will take a look. anonymous added on 2026-10-04 13:25:19: Yes, sorry for the long silence. (I should register somewhere so I get notigication, I suppose.) The attached b964b98d-repro.tcl is a
standalone script for plain wish:
wish9.1 b964b98d-repro.tcl ?iterations?
It is not Aqua-only; the description's "not reproduced on X11" was wrong for
this reduced form. A ttk::panedwindow has four panes, and a <Configure>
binding on one pane destroys that pane. Tk_MoveResizeWindow delivers
<Configure> synchronously (TkDoConfigureNotify), so the binding runs while
Ttk_PlaceContent is placing that very pane from the manager's idle relayout
(ManagerIdleProc -> RecomputeLayout -> PanedPlaceContent -> PlacePanes). The
destroy frees the window and its manager records, and the placement then
reads them.
A release build usually survives the script, because Tcl's allocator keeps
the freed block. With Tcl and Tk 9.1.0 built from the release tarballs with
-DPURIFY and run under valgrind on Linux/X11, 10 iterations give 60 errors
from 5 contexts, for example:
Invalid read of size 1
at Tk_MapWindow (tkWindow.c:1791)
by Tk_MaintainGeometry (tkGeometry.c:446)
by Ttk_PlaceContent (ttkManager.c:372)
by PlacePanes (ttkPanedwindow.c:391)
by PanedPlaceContent (ttkPanedwindow.c:411)
by RecomputeLayout (ttkManager.c:109)
by ManagerIdleProc (ttkManager.c:129)
by TclServiceIdle (tclTimer.c:991)
Address ... is 280 bytes inside a block of size 440 free'd
at free
by TclpFree (tclAlloc.c:724)
by Tcl_EventuallyFree (tclPreserve.c:294)
by Tk_DestroyWindow (tkWindow.c:1764)
by Tk_DestroyObjCmd (tkCmds.c:508)
...
by Tk_BindEvent (tkBind.c:2582)
by TkBindEventProc (tkCmds.c:327)
by Tk_HandleEvent (tkEvent.c:1284)
by TkDoConfigureNotify (tkWindow.c:2374)
On macOS/Aqua with 9.0.4, in July, the same script crashed unpatched wish
with SIGBUS in Tk_MapWindow on every run, and an ASan build reported the
same free and use sites.
The attached b964b98d-9.1.0.patch is the patch already attached here,
brought to 9.1.0 (patch -p1 from the Tk source root):
- ttkManager.c: the manager counts changes to its content list (an epoch),
and code that calls into Tk while holding a content record checks the
count afterwards and stops if the list changed. Stopping is safe because
every change schedules a new relayout. It also skips content and
containers that are being destroyed (TK_ALREADY_DEAD).
- tkGeometry.c: Tk_MaintainGeometry preserves both windows around
Tk_MoveResizeWindow and does not map a window that is being destroyed.
- ttkPanedwindow.c: PlacePanes reads the pane's sash position before
placing, since placing can free the pane.
With the patch, valgrind reports 0 errors for the same run. Tk's test suite
under Xvfb gives the same result with and without it: 9733 tests, the same
15 failures (send, unixWm and wm tests that need a window manager) on both,
and the ttk tests 2042 run, 0 failed.
marc_culler (claiming to be Marc Culler) added on 2026-07-18 21:31:12: Do you have a Tcl script that causes this crash? | |||
Attachments:
- b964b98d-9.1.0.patch [download] added by anonymous on 2026-10-04 13:25:57. [details]
- b964b98d-repro.tcl [download] added by anonymous on 2026-10-04 13:25:57. [details]
- report.tar.gz [download] added by anonymous on 2026-07-06 11:36:53. [details]
- tk-macos-ttk-uaf-9.0.3.patch [download] added by anonymous on 2026-07-05 15:45:26. [details]
