Skip to content
Snippets Groups Projects
Commit 2ab9809a authored by Izzard, Robert Dr (Maths & Physics)'s avatar Izzard, Robert Dr (Maths & Physics)
Browse files

attempt to clean up unfreed memory

parent 5ff3076b
No related branches found
No related tags found
No related merge requests found
......@@ -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)
......
......@@ -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
......
......@@ -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
*/
......
......@@ -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)
{
/*
......
......@@ -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,
......
......@@ -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)
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment