mouse_resize_pane pointers#283 stale-pointer cleanupSeverity: HIGH (corrupted pane geometry on ordinary mouse drags + dangling pointer on mid-drag pane destruction)
Status: ✅ RESOLVED (rev 849:33bd56b0a6aa)
Files:
src/server/server.zig (Server.processInput, clearPaneMouseRefs, clearPaneMouseRefsBulk)src/layout.zig (Layout.hasSplitOnAxis)Related: Bug #283, Bug #511, Bug Index
SIGWINCH: Clicking within 2 cells of the right or bottom edge of a single-pane window (for example, starting a text selection near the right margin) armed border drag-to-resize. Dragging leftward or upward shrank the pane’s terminal grid inside its unchanged layout slot and sent SIGWINCH to the running application, leaving blank space outside the shrunk grid1.destroyPane) or its session was killed (killSession / killAllSessions) before mouse release, Server.mouse_resize_pane was not cleared. If a newly allocated Pane reused the same address, isPaneValid would pass and drag events would resize the wrong pane1.Mouse drag-to-resize (introduced in rev 836:872ab1375c72) had three interacting defects across src/server/server.zig1:
| Defect | Location (Before Fix) | Mechanism |
|---|---|---|
| Unconditional border arming | Server.processInput (left-press branch) |
Checked only m.x >= right_edge -| 2 / m.y >= bottom_edge -| 2 with no check that a split existed on that axis or that the edge was strictly inside window.layout.width / window.layout.height. |
Single-pane resizeTerminal fallback |
Server.processInput (left-drag branch) |
Called resizePaneBy(window, rp, dw, dh). When Layout.resizePane returned false (no matching split), resizePaneBy fell back to pane.resizeTerminal(tw, th) (kept for explicit CLI resize-pane -x/-y in Bug #511), shrinking the terminal under its layout rectangle. |
Missing #283 pointer cleanup |
clearPaneMouseRefs & clearPaneMouseRefsBulk |
Cleared mouse_press_pane and mouse_autoscroll_pane, but omitted the newly added mouse_resize_pane and mouse_resize_axis fields (the exact bug class tracked in Bug #283). |
Implemented in rev 849:33bd56b0a6aa:
Layout (src/layout.zig:303-319)2:
Added Layout.hasSplitOnAxis(self, target, dir) to check whether target has at least one ancestor split matching .horizontal or .vertical.src/server/server.zig:2327-2348)1:
Gated right-edge and bottom-edge arming on both strict interior bounds and an existing split on the dragged axis:
const has_right_split = right_edge < window.layout.width and
window.layout.hasSplitOnAxis(pp, .horizontal);
const has_bottom_split = bottom_edge < window.layout.height and
window.layout.hasSplitOnAxis(pp, .vertical);
src/server/server.zig:2239-2266)1:
Replaced the resizePaneBy call in the drag handler with a direct window.layout.resizePane(rp, dw, dh) followed by window.resize(window.width, window.height), never falling back to pane.resizeTerminal. When !self.isPaneValid(rp), the handler now also resets mouse_resize_pane and mouse_resize_axis to null.#283 parity) (src/server/server.zig:909-920, src/server/server.zig:3852-3858)1:
Cleared mouse_resize_pane and mouse_resize_axis in both clearPaneMouseRefs(pane) (called by destroyPane) and clearPaneMouseRefsBulk() (called by killSession / killAllSessions).src/server/server.zig:
server.server.test.mouse drag-to-resize never fires in a single-pane window or on outer window edges — verifies pressing and dragging within 2 cells of both right and bottom edges in a single-pane window never arms mouse_resize_pane and leaves grid dimensions unchanged.server.server.test.mouse drag-to-resize resizes interior split border and ignores outer edges — verifies dragging an interior divider updates both layout bounds and pane grid widths cleanly, while pressing near the rightmost pane’s outer right edge does not arm a resize.#283 teardown tests (src/server/server.zig:5846-5885):
destroyPane clears stale mouse_autoscroll_pane and mouse_press_pane — bug #283 and killSession clears mouse_autoscroll_pane before tickAutoscroll — bug #283 now both assert mouse_resize_pane == null and mouse_resize_axis == null after teardown.-Doptimize=ReleaseFast test runs pass 1,109/1,109 on both Zig 0.16.0 and Zig 0.17.1 with zero leaks or UAFs.