Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: Memory leaks #610

Merged
merged 6 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ not include contributions from the fast right-hand side function. With this fix,
will see one additional fast right-hand side function evaluation per slow step with the
Hermite interpolation option.

Fixed potential memory leaks and out of bounds array accesses that could occur
in the ARKODE Lagrange interpolation module when changing the method order or
polynomial degree after re-initializing an integrator.

Fixed a CMake configuration issue related to aliasing an `ALIAS` target when
using `ENABLE_KLU=ON` in combination with a static-only build of SuiteSparse.

Expand Down
4 changes: 4 additions & 0 deletions doc/shared/RecentChanges.rst
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ not include contributions from the fast right-hand side function. With this fix,
will see one additional fast right-hand side function evaluation per slow step with the
Hermite interpolation option.

Fixed potential memory leaks and out of bounds array accesses that could occur
in the ARKODE Lagrange interpolation module when changing the method order or
polynomial degree after re-initializing an integrator.

Fixed a CMake configuration issue related to aliasing an ``ALIAS`` target when
using ``ENABLE_KLU=ON`` in combination with a static-only build of SuiteSparse.

Expand Down
1 change: 1 addition & 0 deletions examples/arkode/F2003_serial/ark_roberts_dns_f2003.f90
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ program main
retval = FSUNLinSolFree(sunlinsol_LS)
call FSUNMatDestroy(sunmat_A)
call FN_VDestroy(sunvec_y)
call FN_VDestroy(sunvec_f)
call FN_VDestroy(sunvec_dky)
call FN_VDestroy(sunvec_av)
retval = FSUNContext_Free(sunctx)
Expand Down
3 changes: 2 additions & 1 deletion src/arkode/arkode_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,8 @@ int arkCheckTemporalError(ARKodeMem ark_mem, int* nflagPtr, int* nefPtr,
int arkAccessHAdaptMem(void* arkode_mem, const char* fname, ARKodeMem* ark_mem,
ARKodeHAdaptMem* hadapt_mem);

int arkReplaceAdaptController(ARKodeMem ark_mem, SUNAdaptController C);
int arkReplaceAdaptController(ARKodeMem ark_mem, SUNAdaptController C,
sunbooleantype take_ownership);
int arkSetAdaptivityMethod(void* arkode_mem, int imethod, int idefault, int pq,
sunrealtype adapt_params[3]);
int arkSetAdaptivityFn(void* arkode_mem, ARKAdaptFn hfun, void* h_data);
Expand Down
4 changes: 2 additions & 2 deletions src/arkode/arkode_interp.c
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,7 @@ void arkInterpFree_Lagrange(ARKodeMem ark_mem, ARKInterp I)
{
if (LINT_YHIST(I) != NULL)
{
for (i = 0; i < LINT_NMAX(I); i++)
for (i = 0; i < LINT_NMAXALLOC(I); i++)
{
if (LINT_YJ(I, i) != NULL)
{
Expand Down Expand Up @@ -1039,7 +1039,7 @@ int arkInterpInit_Lagrange(ARKodeMem ark_mem, ARKInterp I, sunrealtype tnew)
}
if (LINT_YHIST(I) != NULL)
{
for (i = 0; i < LINT_NMAX(I); i++)
for (i = 0; i < LINT_NMAXALLOC(I); i++)
{
if (LINT_YJ(I, i) != NULL)
{
Expand Down
7 changes: 4 additions & 3 deletions src/arkode/arkode_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,7 @@ int ARKodeSetAdaptController(void* arkode_mem, SUNAdaptController C)
}

/* Otherwise, call a utility routine to replace the current controller object */
return (arkReplaceAdaptController(ark_mem, C));
return (arkReplaceAdaptController(ark_mem, C, SUNFALSE));
}

/*---------------------------------------------------------------
Expand Down Expand Up @@ -3197,7 +3197,8 @@ int ARKodeWriteParameters(void* arkode_mem, FILE* fp)
object. If a NULL-valued SUNAdaptController is input, the
default will be re-enabled.
---------------------------------------------------------------*/
int arkReplaceAdaptController(ARKodeMem ark_mem, SUNAdaptController C)
int arkReplaceAdaptController(ARKodeMem ark_mem, SUNAdaptController C,
sunbooleantype take_ownership)
{
int retval;
long int lenrw, leniw;
Expand Down Expand Up @@ -3238,7 +3239,7 @@ int arkReplaceAdaptController(ARKodeMem ark_mem, SUNAdaptController C)
}
ark_mem->hadapt_mem->owncontroller = SUNTRUE;
}
else { ark_mem->hadapt_mem->owncontroller = SUNFALSE; }
else { ark_mem->hadapt_mem->owncontroller = take_ownership; }

/* Attach new SUNAdaptController object */
retval = SUNAdaptController_Space(C, &lenrw, &leniw);
Expand Down
7 changes: 4 additions & 3 deletions src/arkode/arkode_mristep_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,12 +266,13 @@ int mriStep_SetAdaptController(ARKodeMem ark_mem, SUNAdaptController C)
/* If this does not have MRI type, then just pass to ARKODE */
if (ctype != SUN_ADAPTCONTROLLER_MRI_H_TOL)
{
return (arkReplaceAdaptController(ark_mem, C));
return (arkReplaceAdaptController(ark_mem, C, SUNFALSE));
}

/* Create the mriStepControl wrapper, and pass that to ARKODE */
/* Create the mriStepControl wrapper, pass that to ARKODE, and give ownership
of the wrapper to ARKODE */
SUNAdaptController Cwrapper = SUNAdaptController_MRIStep(ark_mem, C);
return (arkReplaceAdaptController(ark_mem, Cwrapper));
return (arkReplaceAdaptController(ark_mem, Cwrapper, SUNTRUE));
}

/*---------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -491,8 +491,7 @@ static int fixed_run(void* arkode_mem, N_Vector y, sunrealtype T0, sunrealtype T
sunrealtype abstol = SUN_RCONST(1.e-12);
N_Vector y2 = N_VClone(y);
N_Vector ewt = N_VClone(y);
;
N_Vector vtemp = N_VClone(y);
N_Vector vtemp = N_VClone(y);

// Set array of fixed step sizes to use, storage for corresponding errors/orders
sunrealtype hmax = (Tf - T0) / 400;
Expand Down Expand Up @@ -657,6 +656,7 @@ static int fixed_run(void* arkode_mem, N_Vector y, sunrealtype T0, sunrealtype T

N_VDestroy(y2);
N_VDestroy(ewt);
N_VDestroy(vtemp);
return (0);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,7 @@ static int fixed_run(void* arkode_mem, N_Vector y, sunrealtype T0,

N_VDestroy(y2);
N_VDestroy(ewt);
N_VDestroy(vtemp);
return (0);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,7 @@ int main(int argc, char* argv[])

// Clean up and return
N_VDestroy(y);
N_VDestroy(yref);
MRIStepCoupling_Free(C);
if (As) { SUNMatDestroy(As); }
if (LSs) { SUNLinSolFree(LSs); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,7 @@ int main(int argc, char* argv[])

// Clean up and return
N_VDestroy(y);
N_VDestroy(yref);
MRIStepCoupling_Free(C);
if (As) { SUNMatDestroy(As); }
if (LSs) { SUNLinSolFree(LSs); }
Expand Down
Loading