Skip to content
Open
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
2 changes: 0 additions & 2 deletions src/arkode/arkode_interp.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,6 @@ void arkInterpFree_Hermite(ARKodeMem ark_mem, ARKInterp interp)
interp->ops = NULL;
}
free(interp);
interp = NULL;

return;
}
Expand Down Expand Up @@ -942,7 +941,6 @@ void arkInterpFree_Lagrange(ARKodeMem ark_mem, ARKInterp I)
I->ops = NULL;
}
free(I);
I = NULL;

return;
}
Expand Down
7 changes: 5 additions & 2 deletions src/arkode/arkode_sprkstep.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,15 @@ void* SPRKStepCreate(ARKRhsFn f1, ARKRhsFn f2, sunrealtype t0, N_Vector y0,
{
arkProcessError(ark_mem, ARK_MEM_FAIL, __LINE__, __func__, __FILE__,
MSG_ARK_ARKMEM_FAIL);
ARKodeFree((void**)&ark_mem);
return (NULL);
}
memset(step_mem, 0, sizeof(struct ARKodeSPRKStepMemRec));

/* Attach stepper memory early so generic cleanup can handle partial setup. */
ark_mem->step_free = sprkStep_Free;
ark_mem->step_mem = (void*)step_mem;

/* Allocate vectors in stepper mem */
if (!arkAllocVec(ark_mem, y0, &(step_mem->sdata)))
{
Expand All @@ -119,12 +124,10 @@ void* SPRKStepCreate(ARKRhsFn f1, ARKRhsFn f2, sunrealtype t0, N_Vector y0,
ark_mem->step_setusecompensatedsums = sprkStep_SetUseCompensatedSums;
ark_mem->step_setoptions = sprkStep_SetOptions;
ark_mem->step_resize = sprkStep_Resize;
ark_mem->step_free = sprkStep_Free;
ark_mem->step_setdefaults = sprkStep_SetDefaults;
ark_mem->step_setorder = sprkStep_SetOrder;
ark_mem->step_getnumrhsevals = sprkStep_GetNumRhsEvals;
ark_mem->step_getstageindex = sprkStep_GetStageIndex;
ark_mem->step_mem = (void*)step_mem;

/* Set default values for optional inputs */
retval = sprkStep_SetDefaults((void*)ark_mem);
Expand Down
14 changes: 7 additions & 7 deletions src/cvodes/cvodea.c
Original file line number Diff line number Diff line change
Expand Up @@ -692,21 +692,21 @@ int CVodeCreateB(void* cvode_mem, int lmmB, int* which)
}
ca_mem = cv_mem->cv_adj_mem;

/* Allocate space for new CVodeBMem object */
/* Create and set a new CVODES object for the backward problem */

new_cvB_mem = NULL;
new_cvB_mem = (CVodeBMem)malloc(sizeof(struct CVodeBMemRec));
if (new_cvB_mem == NULL)
cvodeB_mem = CVodeCreate(lmmB, cv_mem->cv_sunctx);
if (cvodeB_mem == NULL)
{
cvProcessError(cv_mem, CV_MEM_FAIL, __LINE__, __func__, __FILE__,
MSGCV_MEM_FAIL);
return (CV_MEM_FAIL);
}

/* Create and set a new CVODES object for the backward problem */
/* Allocate space for new CVodeBMem object */

cvodeB_mem = CVodeCreate(lmmB, cv_mem->cv_sunctx);
if (cvodeB_mem == NULL)
new_cvB_mem = NULL;
new_cvB_mem = (CVodeBMem)malloc(sizeof(struct CVodeBMemRec));
if (new_cvB_mem == NULL)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switching the ordering creates a different potential leak. If the malloc fails, we should call CVodeFree on cvodeB_mem below. I think we should keep the original ordering (create new_cvB_mem first since we'll attach other objects to it) and add free(new_cvB_mem) if CVodeCreate fails.

{
cvProcessError(cv_mem, CV_MEM_FAIL, __LINE__, __func__, __FILE__,
MSGCV_MEM_FAIL);
Expand Down
12 changes: 6 additions & 6 deletions src/idas/idaa.c
Original file line number Diff line number Diff line change
Expand Up @@ -682,18 +682,18 @@ int IDACreateB(void* ida_mem, int* which)
}
IDAADJ_mem = IDA_mem->ida_adj_mem;

/* Allocate a new IDABMem struct. */
new_IDAB_mem = (IDABMem)malloc(sizeof(struct IDABMemRec));
if (new_IDAB_mem == NULL)
/* Allocate the IDAMem struct needed by this backward problem. */
ida_memB = IDACreate(IDA_mem->ida_sunctx);
if (ida_memB == NULL)
{
IDAProcessError(IDA_mem, IDA_MEM_FAIL, __LINE__, __func__, __FILE__,
MSG_MEM_FAIL);
return (IDA_MEM_FAIL);
}

/* Allocate the IDAMem struct needed by this backward problem. */
ida_memB = IDACreate(IDA_mem->ida_sunctx);
if (ida_memB == NULL)
/* Allocate a new IDABMem struct. */
new_IDAB_mem = (IDABMem)malloc(sizeof(struct IDABMemRec));
if (new_IDAB_mem == NULL)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as in CVODES

{
IDAProcessError(IDA_mem, IDA_MEM_FAIL, __LINE__, __func__, __FILE__,
MSG_MEM_FAIL);
Expand Down
2 changes: 1 addition & 1 deletion src/kinsol/kinsol.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,9 +391,9 @@ int KINInit(void* kinmem, KINSysFn func, N_Vector tmpl)
{
KINProcessError(kin_mem, KIN_MEM_FAIL, __LINE__, __func__, __FILE__,
MSG_MEM_FAIL);
SUNDIALS_MARK_FUNCTION_END(KIN_PROFILER);
free(kin_mem);
kin_mem = NULL;
SUNDIALS_MARK_FUNCTION_END(KIN_PROFILER);
return (KIN_MEM_FAIL);
}

Expand Down
11 changes: 5 additions & 6 deletions src/nvector/openmpdev/nvector_openmpdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ N_Vector N_VNew_OpenMPDEV(sunindextype length)
N_VDestroy(v);
return (NULL);
}
NV_DATA_HOST_OMPDEV(v) = data;

/* Allocate memory on device */
dev = omp_get_default_device();
Expand All @@ -206,10 +207,7 @@ N_Vector N_VNew_OpenMPDEV(sunindextype length)
N_VDestroy(v);
return (NULL);
}

/* Attach data */
NV_DATA_HOST_OMPDEV(v) = data;
NV_DATA_DEV_OMPDEV(v) = dev_data;
NV_DATA_DEV_OMPDEV(v) = dev_data;
}

return (v);
Expand Down Expand Up @@ -429,6 +427,8 @@ N_Vector N_VClone_OpenMPDEV(N_Vector w)
return (NULL);
}

NV_DATA_HOST_OMPDEV(v) = data;

/* Allocate memory on device */
dev = omp_get_default_device();
dev_data = omp_target_alloc(length * sizeof(sunrealtype), dev);
Expand All @@ -439,8 +439,7 @@ N_Vector N_VClone_OpenMPDEV(N_Vector w)
}

/* Attach data */
NV_DATA_HOST_OMPDEV(v) = data;
NV_DATA_DEV_OMPDEV(v) = dev_data;
NV_DATA_DEV_OMPDEV(v) = dev_data;
}

return (v);
Expand Down
6 changes: 5 additions & 1 deletion src/sundials/stl/sunstl_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ static inline SUNStlVectorTtype MAKE_NAME(SUNStlVectorTtype,
SUNStlVectorTtype self = (SUNStlVectorTtype)malloc(sizeof(*self));
if (!self) { return NULL; }
self->values = (TTYPE*)malloc(sizeof(TTYPE) * init_capacity);
if (!(self->values)) { return NULL; }
if (!(self->values))
{
free(self);
return NULL;
}
self->size = 0;
self->capacity = init_capacity;
self->destroyValue = destroyValue;
Expand Down
14 changes: 2 additions & 12 deletions src/sundials/sundials_direct.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,13 @@ void SUNDlsMat_DestroyMat(SUNDlsMat A)
A->data = NULL;
free(A->cols);
free(A);
A = NULL;
}

void SUNDlsMat_destroyMat(sunrealtype** a)
{
free(a[0]);
a[0] = NULL;
free(a);
a = NULL;
}

int* SUNDlsMat_NewIntArray(int N)
Expand Down Expand Up @@ -254,17 +252,9 @@ sunrealtype* SUNDlsMat_newRealArray(sunindextype m)
return (v);
}

void SUNDlsMat_DestroyArray(void* V)
{
free(V);
V = NULL;
}
void SUNDlsMat_DestroyArray(void* V) { free(V); }

void SUNDlsMat_destroyArray(void* v)
{
free(v);
v = NULL;
}
void SUNDlsMat_destroyArray(void* v) { free(v); }

void SUNDlsMat_AddIdentity(SUNDlsMat A)
{
Expand Down
1 change: 0 additions & 1 deletion src/sundials/sundials_nvector.c
Original file line number Diff line number Diff line change
Expand Up @@ -1077,7 +1077,6 @@ void N_VDestroyVectorArray(N_Vector* vs, int count)
}

free(vs);
vs = NULL;

return;
}
Expand Down
Loading