diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-20 16:12:18 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-20 16:32:23 -0300 |
| commit | 387297c3bd42c7016e36009ecf8c807259398ac7 (patch) | |
| tree | 93c0e1a34b488bcc83d3b3be7b0fea384727220f /core/views.zig | |
| parent | e4bda7e899089b0c8594ad1b03099402bddeeef1 (diff) | |
| download | pardes-387297c3bd42c7016e36009ecf8c807259398ac7.tar.gz pardes-387297c3bd42c7016e36009ecf8c807259398ac7.zip | |
views.park: the slot it writes is known: the soak's 'allocator leaks detected' at a session's end (g4, seed 7 at 80 ms: Text.reserveSels from setRanges <- normal.replaySels <- a key in insert mode) was the ranges beside a text's primary, made while one view was open, left in a view's slot nothing frees: views.installed returns before `pane.pv_known = p.views_open` while one view is open (views.zig:284), so a pane made then knows no view; a client's join opens another (open sets that view's bit only) and its first input parks the live view (park, views.zig:334: pv[live] = extract(pane), which owns the live text's selections from then on) with the live view's bit still unset, so neither the pane's end (tornDown frees a slot only where its bit is set) nor the view's (dropView, the same) frees them; FIRST the test (views.zig, 'a text's ranges beside its primary, made while one view was open, are freed once another view has been live': a second cursor and a key in insert mode, a view opened and gone into; on the base the testing allocator: 1 leak, 20460 bytes); then the fix: park sets the live view's bit as it fills its slot (one line); a user: a session that ran with one client and later took a second, every pane opened before it that had several cursors leaked its ranges (about 20 KB a pane) until the session's end
Diffstat (limited to 'core/views.zig')
| -rw-r--r-- | core/views.zig | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/core/views.zig b/core/views.zig index 89dcb454..3c2248d7 100644 --- a/core/views.zig +++ b/core/views.zig @@ -324,7 +324,11 @@ pub fn gone(p: *Pardes, id: usize) void { fn park(p: *Pardes) void { for (p.panes) |s| if (s) |pane| { + // The slot owns the live text's selections now: known, so that + // the pane's end or the view's frees them (a pane made while one + // view was open had no view known). pane.pv[p.live] = extract(pane); + pane.pv_known |= bit(p.live); }; } @@ -601,6 +605,25 @@ test "each view has its own cursor and scroll, and an edit in one is in the othe try testing.expectEqual(Text.Mode.normal, pane.body.mode); } +// A pane made while one view is open is its share there alone; the +// ranges beside its primary that a key makes are the live text's, and +// the view's slot owns them once another view is live (park): freed with +// the pane, or with that view. +test "a text's ranges beside its primary, made while one view was open, are freed once another view has been live" { + const gpa = testing.allocator; + const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24 }); + defer p.deinit(); + const text = try numbered(gpa, 20); + defer gpa.free(text); + const pane = try p.setTestFile(text); + // A second cursor below, and a key typed in insert mode at both. + typeKeys(p, "Cix"); + escape(p); + try testing.expect(pane.body.sels.len > 0); + try testing.expectEqual(@as(?View.Id, .at(1)), p.openView()); + p.toView(.at(1)); +} + test "each view has its own layout and focus over the same panes" { const gpa = testing.allocator; const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 100, .rows = 30 }); |
