From 3d9a429499841cca83b5c8359ea7e2b78509601f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Fri, 14 Oct 2022 18:00:48 +0200 Subject: [PATCH] term: reverse scroll: free scrolled out lines This ensures *everything* in the circular scrollback history, after the bottom of the screen, is either NULL rows, or belong to the scrollback *history* (as opposed to the future history). This fixes an issue when calculating the scrollback start, which for example would trigger a crash when moving the viewport (i.e. scrolling with the mouse, or PgUp/PgDown). Closes #1190 --- terminal.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/terminal.c b/terminal.c index 16486d82..380f0d4a 100644 --- a/terminal.c +++ b/terminal.c @@ -2676,6 +2676,18 @@ term_scroll_reverse_partial(struct terminal *term, selection_scroll_down(term, rows); } + /* Unallocate scrolled out lines */ + for (int r = region.end - rows; r < region.end; r++) { + const int abs_r = grid_row_absolute(term->grid, r); + struct row *row = term->grid->rows[abs_r]; + + grid_row_free(row); + term->grid->rows[abs_r] = NULL; + + if (term->render.last_cursor.row == row) + term->render.last_cursor.row = NULL; + } + sixel_scroll_down(term, rows); bool view_follows = term->grid->view == term->grid->offset;