szn

Bug 446 — VS16 promotion erase sites skip the sixel refcount decrement

446. Sixel refcount leak when a promoted base cell carried a sixel marker

Severity: LOW Status: Fixed

Symptoms

None observed in production — the trigger requires an application to emit U+FE0F immediately after a cell belonging to a sixel image while variation-selector-always-wide is on. When it fires, the erased cell’s sixel image reference is dropped from the grid without decrementing sixel_refcounts, so isImageReferenced stays true and the image is retained (memory held until a resize/eviction pass frees it).


Root Cause Analysis

Bug #225 established the invariant: any overwrite or erase of a cell must call decrementMainGridRef first (combining-character appends are the sole exception, because they modify the cell in place without erasing the marker). The promotion code carefully honours this for the cells it moves the base char onto and for the padding cells it writes (decrements at src/screen.zig:742, 749, 787, 800, 807) — but the two setCell(..., self.eraseCell()) calls that blank the base cell’s original position (the wrapped-line path and the line-wrap branch) omit it, even though the comb-append guard (char != ' ' and char != 0) lets sixel marker cells through.


Solution

  1. Added decrementMainGridRef immediately before both erase overwrites:
    • wrapped-line path (blanking the base at the end of the previous line),
    • same-line wrap branch (blanking the base before moving it to the next line).
  2. No dedicated unit test: the sixel marker + trailing VS16 adjacency is not constructible through the public write path without a full sixel image fixture, and the fix is a one-line application of the existing bug #225 convention verified by the existing refcount test suite.