szn

Bug 454 — Screen.flushPendingSixel leaks pending sixel data when cell size unknown

454. flushPendingSixel drops ownership before the known-guard

Severity: MEDIUM Status: ✅ FIXED Files: src/screen.zig


Symptoms

Repeated sixel images arriving before the terminal’s XTWINOPS cell-size reply slowly grow server memory; no crash, just unbounded leak under sixel-heavy workloads.


Root Cause Analysis

In src/screen.zig:203-206:

pub fn flushPendingSixel(self: *Screen) void {
    const pending = self.pending_sixel orelse return;
    self.pending_sixel = null;
    if (!self.cell_size_known) return;
  1. Ownership is taken (= null) before the guard.
  2. On the !known path pending.data is neither re-buffered nor freed — the pointer is lost.
  3. Caller updateCellSize:192-198 calls it unconditionally; doc says “must only be called once known is true” but nothing enforces it.

Proposed Fix

Re-buffer on the unknown path (self.pending_sixel = pending; return;) or only take ownership after the guard. Add a regression test that calls flushPendingSixel with cell_size_known=false and asserts no leak / still pending.