Skip to content
Snippets Groups Projects
Commit 0bea33bc authored by Andreas Gattringer's avatar Andreas Gattringer
Browse files

fixed cleanup-on-exit crash

parent 61c6b31d
No related branches found
No related tags found
No related merge requests found
......@@ -251,30 +251,33 @@ void cleanup_grid_seeds_and_juveniles(struct cats_grid *grid)
free_grid(&grid->seeds_produced, grid->dimension.rows);
free_grid(&grid->dispersed_seeds, grid->dimension.rows);
if (grid->seed_bank) {
for (cats_dt_coord row = 0; row < grid->dimension.rows; row++) {
for (cats_dt_coord col = 0; col < grid->dimension.cols; col++) {
destroy_seed_structure(grid, row, col);
}
free(grid->juveniles[row]);
free(grid->seed_bank[row]);
}
}
if (grid->seed_bank) {
if (grid->juveniles) {
for (cats_dt_coord row = 0; row < grid->dimension.rows; row++) {
for (cats_dt_coord col = 0; col < grid->dimension.cols; col++) {
destroy_juveniles(grid, row, col);
}
free(grid->juveniles[row]);
grid->juveniles[row] = NULL;
}
}
free(grid->seed_bank);
free(grid->juveniles);
free(grid->seeds_produced);
grid->juveniles = NULL;
grid->seed_bank = NULL;
}
......
......@@ -114,6 +114,7 @@ void destroy_juveniles(const struct cats_grid *grid, const cats_dt_coord row, co
assert(stages >= 0);
if (grid->juveniles[row] && grid->juveniles[row][col]) {
memset(grid->juveniles[row][col], 0, stages * sizeof(cats_dt_population));
free(grid->juveniles[row][col]);
grid->juveniles[row][col] = NULL;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment