diff --git a/src/events/catch_events.c b/src/events/catch_events.c index 8b20705b0e062956827c038f2873cb27fe6b8cb5..b2dac3698b3dbca6d8a512d48018ccef9ad97b35 100644 --- a/src/events/catch_events.c +++ b/src/events/catch_events.c @@ -34,11 +34,18 @@ void catch_events(struct stardata_t * RESTRICT const stardata) */ if(stardata->preferences->save_pre_events_stardata == TRUE) { + if(stardata->pre_events_stardata != NULL) + { + /* this should not happen! */ + free_stardata(&stardata->pre_events_stardata); + } stardata->pre_events_stardata = new_stardata(stardata->preferences); copy_stardata(stardata, stardata->pre_events_stardata, COPY_STARDATA_PREVIOUS_NONE, COPY_STARDATA_PERSISTENT_NONE); + /* prevent recursion */ + stardata->pre_events_stardata->pre_events_stardata = NULL; } if(stardata->preferences->catch_events_function != NULL) diff --git a/src/evolution/evolution_rejected.c b/src/evolution/evolution_rejected.c index 9945db89c21771f8dd8f0587b1cd6622b90d93a9..b01ce8360270e7ca8063a098c55acef060acd50a 100644 --- a/src/evolution/evolution_rejected.c +++ b/src/evolution/evolution_rejected.c @@ -42,6 +42,16 @@ int evolution_rejected(struct stardata_t * RESTRICT const stardata) stardata->previous_stardata->model.supernova ); + /* + * Free any pre-event data + */ + if(stardata->pre_events_stardata != NULL) + { + printf("reject free pre %p\n", + (void*)stardata->pre_events_stardata); + free_stardata(&stardata->pre_events_stardata); + } + /* * Restore the previous stardata and reduce the timestep * if reject == REJECTION_RESULT_SHORTEN_TIMESTEP diff --git a/src/evolution/evolution_split.c b/src/evolution/evolution_split.c index 0c934cfd81514a2b1a9460823d9ab99259e83d38..ba894bf94f4454abb6034c3bb19aef88bcf7906b 100644 --- a/src/evolution/evolution_split.c +++ b/src/evolution/evolution_split.c @@ -147,6 +147,7 @@ int evolution_split(struct stardata_t * RESTRICT const stardata, erase_events(stardata); free_previous_stardatas(stardata); + free_stardata(&stardata->pre_events_stardata); copy_stardata(p->stardata, stardata, @@ -186,6 +187,7 @@ int evolution_split(struct stardata_t * RESTRICT const stardata, /* clean up memory */ struct stardata_t * s = stardata->preferences->splitinfo[stardata->preferences->current_splitdepth]->stardata; + free_stardata(&stardata->pre_events_stardata); free_previous_stardatas(s); Safe_free(s); Safe_free(stardata->preferences->splitinfo[stardata->preferences->current_splitdepth]); @@ -225,6 +227,12 @@ int evolution_split(struct stardata_t * RESTRICT const stardata, /* should be rerun this many times */ p->count = split - 1; + /* + * Free the pre-events stardata, as this event + * will be rerun + */ + free_stardata(&stardata->pre_events_stardata); + /* * allocate space */ @@ -240,6 +248,8 @@ int evolution_split(struct stardata_t * RESTRICT const stardata, COPY_STARDATA_PERSISTENT_FROM_POINTER ); + + /* * Keep preferences */ diff --git a/src/evolution/evolve_system_binary_c.c b/src/evolution/evolve_system_binary_c.c index 0e9891744a7dda7ed1e1ea9a6a1e698cadbd7f09..143fd4c2e03dea598d2b788142ec30f664790019 100644 --- a/src/evolution/evolve_system_binary_c.c +++ b/src/evolution/evolve_system_binary_c.c @@ -229,7 +229,6 @@ int evolve_system_binary_c(struct stardata_t * RESTRICT const stardata) /* * This step has been rejected. */ - if(reject == EVOLUTION_REJECT_AND_RETURN_NOW) { /* diff --git a/src/memory/deep_copy_stardata.c b/src/memory/deep_copy_stardata.c index 53847ce53c330f64e5cfd3b4a2665261cbae601e..2462627669a9172ee8b9f283ef8532cfb2bde451 100644 --- a/src/memory/deep_copy_stardata.c +++ b/src/memory/deep_copy_stardata.c @@ -52,6 +52,11 @@ void * deep_copy_stardata(struct stardata_t * const src, */ memcpy(dest,src,sizeof(struct stardata_t)); + /* + * Don't keep pre_events_stardata + */ + dest->pre_events_stardata = NULL; + #ifdef MINT Cprint("post-memcpy old mint %p, new mint %p (should be same)\n", (void*)src->star[0].mint, diff --git a/src/memory/free_stardata.c b/src/memory/free_stardata.c index 16eb74a3a2adc1dc0b9369225ac345569abf3ace..66475ec441817cdfc705f4449683cad5875d40a3 100644 --- a/src/memory/free_stardata.c +++ b/src/memory/free_stardata.c @@ -15,6 +15,10 @@ void free_stardata(struct stardata_t ** sp) { free_star_contents(&stardata->star[k]); } + if(stardata->pre_events_stardata != NULL) + { + free_stardata(&stardata->pre_events_stardata); + } #ifdef ORBITING_OBJECTS if(stardata->common.orbiting_object != NULL) {