Severity: LOW (latent — no live leak today, but a contract trap)
Status: 🟢 FIXED
Files: src/screen.zig:354-357
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.
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.
src/screen.zig, updated placeSixelImage’s errdefer to deinitialize sixel_images[slot] (freeing dcs_bytes), zero the refcount, null the slot, and call clearSixelMarkerCells(id) to roll back any marker cells placed on the grid prior to error.placeSixelImage and addSixelImage.dcs_bytes frees on error in addSixelImage and flushPendingSixel so placeSixelImage strictly manages ownership of dcs_bytes.src/screen.zig testing that placeSixelImage frees image bytes, zeroes slot/refcount, and cleans up marker cells when an error occurs during grid scrolling.