diff --git a/src/cache.h b/src/cache.h index 6332f1470564a3a0869b851bd7cd9853d922c143..19d61b657b3aa1fe8675ee413fcde146071381e9 100644 --- a/src/cache.h +++ b/src/cache.h @@ -162,4 +162,22 @@ __attribute__((always_inline)) INLINE void cache_read_particles( #endif } +/** + * @brief Clean the memory allocated by a #cache object. + * + * @param c The #cache to clean. + */ +static INLINE void cache_clean(struct cache *c) { + if (c->count > 0) { + free(c->x); + free(c->y); + free(c->z); + free(c->m); + free(c->vx); + free(c->vy); + free(c->vz); + free(c->h); + } +} + #endif /* SWIFT_CACHE_H */ diff --git a/src/engine.c b/src/engine.c index c10659f96921b27e0539b7657386fec1dcafdcfb..d08c16e79bc49c51e45da6a94abbfccb8fae8b2e 100644 --- a/src/engine.c +++ b/src/engine.c @@ -2381,7 +2381,7 @@ void engine_collect_kick(struct cell *c) { integertime_t ti_end_min = max_nr_timesteps; /* Only do something is the cell is non-empty */ - if (c->count != 0 || c->gcount != 0) { + if (c->count != 0 || c->gcount != 0 || c->scount != 0) { /* If this cell is not split, I'm in trouble. */ if (!c->split) error("Cell is not split."); @@ -3555,6 +3555,8 @@ void engine_compute_next_snapshot_time(struct engine *e) { */ void engine_clean(struct engine *e) { + for (int i = 0; i < e->nr_threads; ++i) cache_clean(&e->runners[i].par_cache); + free(e->runners); free(e->snapshotUnits); free(e->links); scheduler_clean(&e->sched);