szn

Bug 501 — placeSixelImage errdefer leaks image bytes (latent)

501. Slot dropped, data not freed, markers/anchors left behind

Severity: LOW (latent — no live leak today, but a contract trap) Status: 🟢 FIXED Files: src/screen.zig:354-357

Problem

errdefer {
    self.sixel_images[slot] = null;
    self.sixel_refcounts[slot] = 0;
}

If a later try self.grid.scrollUp() (or similar fallible step) fails after the SixelImage (with its up-to-8 MiB data buffer) is installed, the errdefer drops the slot and zeroes the refcount without freeing SixelImage.data — and without rolling back any marker cells/anchors already placed. Today’s callers free dcs_bytes themselves on error, so there is no live leak; but the ownership contract is a trap for the next caller, and partially-placed markers/anchors are left behind regardless.

Proposed Fix

Free the image data inside the errdefer (deinit the SixelImage rather than just nulling the slot), and document the ownership contract: on error, placeSixelImage leaves no markers, no anchors, and no allocated image behind. Consider also rolling back already-placed marker cells.

Resolution