fix memory leaks in pair style meam/spline
This commit is contained in:
@ -57,6 +57,7 @@ PairMEAMSpline::PairMEAMSpline(LAMMPS *lmp) : Pair(lmp)
|
|||||||
|
|
||||||
nelements = 0;
|
nelements = 0;
|
||||||
elements = NULL;
|
elements = NULL;
|
||||||
|
map = NULL;
|
||||||
|
|
||||||
Uprime_values = NULL;
|
Uprime_values = NULL;
|
||||||
nmax = 0;
|
nmax = 0;
|
||||||
@ -65,6 +66,14 @@ PairMEAMSpline::PairMEAMSpline(LAMMPS *lmp) : Pair(lmp)
|
|||||||
|
|
||||||
comm_forward = 1;
|
comm_forward = 1;
|
||||||
comm_reverse = 0;
|
comm_reverse = 0;
|
||||||
|
|
||||||
|
phis = NULL;
|
||||||
|
Us = NULL;
|
||||||
|
rhos = NULL;
|
||||||
|
fs = NULL;
|
||||||
|
gs = NULL;
|
||||||
|
|
||||||
|
zero_atom_energies = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------- */
|
||||||
@ -332,6 +341,8 @@ void PairMEAMSpline::allocate()
|
|||||||
allocated = 1;
|
allocated = 1;
|
||||||
int n = nelements;
|
int n = nelements;
|
||||||
|
|
||||||
|
memory->destroy(setflag);
|
||||||
|
memory->destroy(cutsq);
|
||||||
memory->create(setflag,n+1,n+1,"pair:setflag");
|
memory->create(setflag,n+1,n+1,"pair:setflag");
|
||||||
memory->create(cutsq,n+1,n+1,"pair:cutsq");
|
memory->create(cutsq,n+1,n+1,"pair:cutsq");
|
||||||
|
|
||||||
@ -339,14 +350,21 @@ void PairMEAMSpline::allocate()
|
|||||||
//Change the functional form
|
//Change the functional form
|
||||||
//f_ij->f_i
|
//f_ij->f_i
|
||||||
//g_i(cos\theta_ijk)->g_jk(cos\theta_ijk)
|
//g_i(cos\theta_ijk)->g_jk(cos\theta_ijk)
|
||||||
|
delete[] phis;
|
||||||
|
delete[] Us;
|
||||||
|
delete[] rhos;
|
||||||
|
delete[] fs;
|
||||||
|
delete[] gs;
|
||||||
phis = new SplineFunction[nmultichoose2];
|
phis = new SplineFunction[nmultichoose2];
|
||||||
Us = new SplineFunction[n];
|
Us = new SplineFunction[n];
|
||||||
rhos = new SplineFunction[n];
|
rhos = new SplineFunction[n];
|
||||||
fs = new SplineFunction[n];
|
fs = new SplineFunction[n];
|
||||||
gs = new SplineFunction[nmultichoose2];
|
gs = new SplineFunction[nmultichoose2];
|
||||||
|
|
||||||
|
delete[] zero_atom_energies;
|
||||||
zero_atom_energies = new double[n];
|
zero_atom_energies = new double[n];
|
||||||
|
|
||||||
|
delete[] map;
|
||||||
map = new int[n+1];
|
map = new int[n+1];
|
||||||
for (int i=0; i <= n; ++i) map[i] = -1;
|
for (int i=0; i <= n; ++i) map[i] = -1;
|
||||||
}
|
}
|
||||||
@ -470,6 +488,9 @@ void PairMEAMSpline::read_file(const char* filename)
|
|||||||
if (nelements < 1)
|
if (nelements < 1)
|
||||||
error->one(FLERR, "Invalid number of atomic species on"
|
error->one(FLERR, "Invalid number of atomic species on"
|
||||||
" meam/spline line in potential file");
|
" meam/spline line in potential file");
|
||||||
|
if (elements)
|
||||||
|
for (int i = 0; i < nelements; i++) delete [] elements[i];
|
||||||
|
delete [] elements;
|
||||||
elements = new char*[nelements];
|
elements = new char*[nelements];
|
||||||
for (int i=0; i<nelements; ++i) {
|
for (int i=0; i<nelements; ++i) {
|
||||||
ptr = strtok(NULL," \t\n\r\f");
|
ptr = strtok(NULL," \t\n\r\f");
|
||||||
|
|||||||
Reference in New Issue
Block a user