diff --git a/src/cats/plants/plant_structures.c b/src/cats/plants/plant_structures.c index 590704b600e32d7450f6bd166d399878d5f857d7..be4613afb7be7f1cc6d76aa7f376c241dd2b8f10 100644 --- a/src/cats/plants/plant_structures.c +++ b/src/cats/plants/plant_structures.c @@ -106,13 +106,14 @@ void destroy_juveniles(const struct cats_grid *grid, const cats_dt_coord row, co assert(row >= 0 && row < grid->dimension.rows); assert(col >= 0 && col < grid->dimension.cols); assert(grid->juveniles != NULL); + + const int32_t max_age_of_maturity = get_vital_age(grid, VA_AGE_OF_MATURITY_MAX); const int32_t stages = max_age_of_maturity + 1; assert(stages >= 0); - if (grid->juveniles[row][col]) { - memset(grid->juveniles[row][col], 0, stages * sizeof(cats_dt_population)); + if (grid->juveniles[row] && grid->juveniles[row][col]) { free(grid->juveniles[row][col]); grid->juveniles[row][col] = NULL; }