From 2cf3a9dd96eb0caa2546be79a0e8af21773b1c75 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Mon, 9 Mar 2009 06:49:11 +0100 Subject: [PATCH] Bugfix: Correctly free containers when shrinking the table --- src/table.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/table.c b/src/table.c index fe50438e..91aabbac 100644 --- a/src/table.c +++ b/src/table.c @@ -87,14 +87,24 @@ void expand_table_cols(Workspace *workspace) { static void shrink_table_cols(Workspace *workspace) { workspace->cols--; + + /* Free the containers */ + for (int rows = 0; rows < workspace->rows; rows++) + free(workspace->table[workspace->cols][rows]); + + /* Free the container-pointers */ free(workspace->table[workspace->cols]); + + /* Re-allocate the table */ workspace->table = realloc(workspace->table, sizeof(Container**) * workspace->cols); } static void shrink_table_rows(Workspace *workspace) { workspace->rows--; - for (int cols = 0; cols < workspace->cols; cols++) + for (int cols = 0; cols < workspace->cols; cols++) { + free(workspace->table[cols][workspace->rows]); workspace->table[cols] = realloc(workspace->table[cols], sizeof(Container*) * workspace->rows); + } } -- 2.39.5