Bugfix: Correctly free containers when shrinking the table

This commit is contained in:
Michael Stapelberg 2009-03-09 06:49:11 +01:00
parent 65595c61a8
commit 2cf3a9dd96
1 changed files with 11 additions and 1 deletions

View File

@ -87,15 +87,25 @@ void expand_table_cols(Workspace *workspace) {
static void shrink_table_cols(Workspace *workspace) { static void shrink_table_cols(Workspace *workspace) {
workspace->cols--; 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]); free(workspace->table[workspace->cols]);
/* Re-allocate the table */
workspace->table = realloc(workspace->table, sizeof(Container**) * workspace->cols); workspace->table = realloc(workspace->table, sizeof(Container**) * workspace->cols);
} }
static void shrink_table_rows(Workspace *workspace) { static void shrink_table_rows(Workspace *workspace) {
workspace->rows--; 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); workspace->table[cols] = realloc(workspace->table[cols], sizeof(Container*) * workspace->rows);
} }
}
/* /*