Unverified Commit 68d94f9b authored by Axel Kohlmeyer's avatar Axel Kohlmeyer
Browse files

fix memory leaks in pair style meam/spline

parent dff8a50a
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -57,6 +57,7 @@ PairMEAMSpline::PairMEAMSpline(LAMMPS *lmp) : Pair(lmp)

  nelements = 0;
  elements = NULL;
  map = NULL;

  Uprime_values = NULL;
  nmax = 0;
@@ -65,6 +66,14 @@ PairMEAMSpline::PairMEAMSpline(LAMMPS *lmp) : Pair(lmp)

  comm_forward = 1;
  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;
  int n = nelements;

  memory->destroy(setflag);
  memory->destroy(cutsq);
  memory->create(setflag,n+1,n+1,"pair:setflag");
  memory->create(cutsq,n+1,n+1,"pair:cutsq");

@@ -339,14 +350,21 @@ void PairMEAMSpline::allocate()
  //Change the functional form
  //f_ij->f_i
  //g_i(cos\theta_ijk)->g_jk(cos\theta_ijk)
  delete[] phis;
  delete[] Us;
  delete[] rhos;
  delete[] fs;
  delete[] gs;
  phis = new SplineFunction[nmultichoose2];
  Us = new SplineFunction[n];
  rhos = new SplineFunction[n];
  fs = new SplineFunction[n];
  gs = new SplineFunction[nmultichoose2];

  delete[] zero_atom_energies;
  zero_atom_energies = new double[n];

  delete[] map;
  map = new int[n+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)
        error->one(FLERR, "Invalid number of atomic species on"
                   " meam/spline line in potential file");
      if (elements)
        for (int i = 0; i < nelements; i++) delete [] elements[i];
      delete [] elements;
      elements = new char*[nelements];
      for (int i=0; i<nelements; ++i) {
        ptr = strtok(NULL," \t\n\r\f");