fix a couple memory leaks

This commit is contained in:
Mitchell Hashimoto
2022-05-09 20:50:06 -07:00
parent 32ccfee94f
commit e3adedf6e6

View File

@ -374,6 +374,12 @@ pub fn eraseDisplay(
cell.char = 0; cell.char = 0;
} }
// Remaining lines are deallocated
if (self.cursor.y + 1 < self.screen.items.len) {
for (self.screen.items[self.cursor.y + 1 .. self.screen.items.len]) |*below|
below.deinit(alloc);
}
// Shrink // Shrink
self.screen.shrinkRetainingCapacity(self.cursor.y + 1); self.screen.shrinkRetainingCapacity(self.cursor.y + 1);
}, },
@ -555,6 +561,10 @@ pub fn scrollDown(self: *Terminal, alloc: Allocator) !void {
// Add one more item if we aren't at the max // Add one more item if we aren't at the max
if (self.screen.items.len < self.rows) { if (self.screen.items.len < self.rows) {
self.screen.items.len += 1; self.screen.items.len += 1;
} else {
// We have the max, we need to deinitialize the last row because
// we're going to overwrite it.
self.screen.items[self.screen.items.len - 1].deinit(alloc);
} }
// Shift everything down // Shift everything down