From 3ba03901b893abcdb4433d71d0b6568abceba770 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Tue, 18 Oct 2022 18:31:18 +0200 Subject: [PATCH] =?UTF-8?q?pgo:=20don=E2=80=99t=20re-use=20the=20rows=20be?= =?UTF-8?q?tween=20the=20=E2=80=98normal=E2=80=99=20and=20=E2=80=98alt?= =?UTF-8?q?=E2=80=99=20grids?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This used to work because we never free:d any of the rows. Now however, we do free (some of) them when reverse scrolling. This means we can no longer re-use the rows between the two screens. Closes #1196 --- pgo/pgo.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/pgo/pgo.c b/pgo/pgo.c index 7f6f758b..b41b5850 100644 --- a/pgo/pgo.c +++ b/pgo/pgo.c @@ -228,10 +228,14 @@ main(int argc, const char *const *argv) return EXIT_FAILURE; } - struct row **rows = calloc(grid_row_count, sizeof(rows[0])); + struct row **normal_rows = calloc(grid_row_count, sizeof(normal_rows[0])); + struct row **alt_rows = calloc(grid_row_count, sizeof(alt_rows[0])); + for (int i = 0; i < grid_row_count; i++) { - rows[i] = calloc(1, sizeof(*rows[i])); - rows[i]->cells = calloc(col_count, sizeof(rows[i]->cells[0])); + normal_rows[i] = calloc(1, sizeof(*normal_rows[i])); + normal_rows[i]->cells = calloc(col_count, sizeof(normal_rows[i]->cells[0])); + alt_rows[i] = calloc(1, sizeof(*alt_rows[i])); + alt_rows[i]->cells = calloc(col_count, sizeof(alt_rows[i]->cells[0])); } struct config conf = { @@ -254,14 +258,14 @@ main(int argc, const char *const *argv) .normal = { .num_rows = grid_row_count, .num_cols = col_count, - .rows = rows, - .cur_row = rows[0], + .rows = normal_rows, + .cur_row = normal_rows[0], }, .alt = { .num_rows = grid_row_count, .num_cols = col_count, - .rows = rows, - .cur_row = rows[0], + .rows = alt_rows, + .cur_row = alt_rows[0], }, .scale = 1, .width = col_count * 8, @@ -371,11 +375,17 @@ out: tll_free(wayl.terms); for (int i = 0; i < grid_row_count; i++) { - free(rows[i]->cells); - free(rows[i]); + if (normal_rows[i] != NULL) + free(normal_rows[i]->cells); + free(normal_rows[i]); + + if (alt_rows[i] != NULL) + free(alt_rows[i]->cells); + free(alt_rows[i]); } - free(rows); + free(normal_rows); + free(alt_rows); close(lower_fd); close(upper_fd); return ret;