Skip to content

Commit

Permalink
SundialsIntegrator: Fix memory deallocation
Browse files Browse the repository at this point in the history
nv_many_array is allocated with new[]. So it must be deallocated with
delete[]. Therefore we cannot call Sundials's N_VDestroyVectorArray that
uses std::free.
  • Loading branch information
WeiqunZhang committed Aug 19, 2023
1 parent a4fb1d4 commit 0607ef0
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Src/Extern/SUNDIALS/AMReX_SundialsIntegrator.H
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,10 @@ public:
}

// Clean up allocated memory
N_VDestroyVectorArray(nv_many_arr, NVar);
for (int i = 0; i < Nvar; ++i) {
N_VDestroy(nv_many_arr[i]);
}
delete[] nv_many_arr;
N_VDestroy(nv_S);
N_VDestroy(nv_stage_data);

Expand Down Expand Up @@ -623,7 +626,10 @@ public:
}

// Clean up allocated memory
N_VDestroyVectorArray(nv_many_arr, NVar);
for (int i = 0; i < Nvar; ++i) {
N_VDestroy(nv_many_arr[i]);
}
delete[] nv_many_arr;
N_VDestroy(nv_S);
N_VDestroy(nv_stage_data);

Expand Down

0 comments on commit 0607ef0

Please sign in to comment.