From 1e8a1bc591eb26bb0acee50e349a604d2f7df593 Mon Sep 17 00:00:00 2001 From: Matthieu Schaller <matthieu.schaller@durham.ac.uk> Date: Mon, 23 Jan 2017 20:48:16 +0000 Subject: [PATCH] Clean up memory from the particle at the end of a run. Helps with sanitizer work. --- src/cache.h | 18 ++++++++++++++++++ src/engine.c | 4 +++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/cache.h b/src/cache.h index 6332f14705..19d61b657b 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 c10659f969..d08c16e79b 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); -- GitLab