Tk Source Code

View Ticket
Login
Ticket UUID: 86dbc4064aa9184101f072a3dbd2fd3e6eca409d
Title: Wayland branch: use after free of the container of a subwindow (pack.test crashes)
Type: Bug Version: wayland
Submitter: serhiy.storchaka Created on: 2026-10-14 19:51:50
Subsystem: (unused) Assigned To: aku
Priority: 5 Medium Severity: Important
Status: Closed Last Modified: 2026-10-22 17:22:37
Resolution: Fixed Closed By: serhiy.storchaka
    Closed on: 2026-10-14 20:25:33
Description:

On the wayland branch ([b5ff45d7dc]), pack.test crashes after pack-15.5 under headless sway:

#0  TkWaylandQueueExposeEvent (winPtr=..., ...) at wayland/tkWaylandNotify.c:618
#1  XMoveResizeWindow (...) at wayland/tkWaylandWm.c:4916
#2  Tk_MoveResizeWindow (...) at generic/tkWindow.c:2083
#3  ArrangePacking (...) at generic/tkPack.c:758

addClipRect() in wayland/tkWaylandSubwindows.c keeps a pointer to the window whose clipping rectangles include a subwindow in privatePtr->container of the subwindow, and nothing clears it when that window is destroyed. With pack -in it is not the parent of the subwindow, so it can be destroyed first, and the next move or resize of the subwindow (XMoveWindow, XResizeWindow, XMoveResizeWindow) queues an Expose event on the freed window.

Proposed fix in branch wayland-container-id, [0fd5f0011a]: the window ID of the container is kept instead, and TkWaylandGetContainer() looks it up with Tk_IdToWindow(), which finds no destroyed window. pack.test then runs to the end.

User Comments: serhiy.storchaka added on 2026-10-14 20:25:33:

Thanks. Merged into wayland in [bab7d255e2].


kevin_walzer added on 2026-10-14 20:19:02:
Fine to merge this branch - thank you.

serhiy.storchaka added on 2026-10-14 20:17:40:

Yes: the crash is gone, which is what this branch fixes. Most of the remaining failures of pack.test come from the size of the toplevel (see [041f2f1131]) and from font metrics.


kevin_walzer added on 2026-10-14 20:06:00:
In this branch, pack.test has 84 failures, but no crashes. Progress?