szn

Bug 399 — addSixelImage ownership inversion

399. addSixelImage ownership inversion: the #269 errdefer frees dcs_bytes after placeSixelImage has already stored it in sixel_images

Severity: HIGH Status: ✅ RESOLVED

addSixelImage begins with errdefer self.allocator.free(dcs_bytes) (:223) — correct until ownership transfers. placeSixelImage stores the slice into the slot at :340 (self.sixel_images[slot] = SixelImage{ .data = dcs_bytes, ... }) and then performs fallible work: try self.grid.scrollUp() in the marker loop (:367) and the final repositioning loop. If either fails (OOM from the backing GPA), the errdefer frees bytes the slot still references:

flushPendingSixel (:205-210) has the same shape and its comment merely acknowledges the loss.

Fix: disarm the errdefer the moment the slice is placed into the slot (pass a *bool owned, or split placement so the first fallible call happens before storing).