Unverified Commit db469b5c authored by Axel Kohlmeyer's avatar Axel Kohlmeyer
Browse files

plug memory leak in AtomVec classes

parent 49af2c25
Loading
Loading
Loading
Loading
+38 −0
Changes for src/atom_vec.cpp: 38 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -90,9 +90,47 @@ AtomVec::AtomVec(LAMMPS *lmp) : Pointers(lmp)

AtomVec::~AtomVec()
{
  int datatype,cols,maxcols;
  void *pdata;

  for (int i = 0; i < nargcopy; i++) delete [] argcopy[i];
  delete [] argcopy;

  for (int i = 0; i < ngrow; i++) {
    pdata = mgrow.pdata[i];
    datatype = mgrow.datatype[i];
    cols = mgrow.cols[i];
    const int nthreads = threads[i] ? comm->nthreads : 1;
    if (datatype == Atom::DOUBLE) {
      if (cols == 0)
        memory->destroy(*((double **) pdata));
      else if (cols > 0)
        memory->destroy(*((double ***) pdata));
      else {
        maxcols = *(mgrow.maxcols[i]);
        memory->destroy(*((double ***) pdata));
      }
    } else if (datatype == Atom::INT) {
      if (cols == 0)
        memory->destroy(*((int **) pdata));
      else if (cols > 0)
        memory->destroy(*((int ***) pdata));
      else {
        maxcols = *(mgrow.maxcols[i]);
        memory->destroy(*((int ***) pdata));
      }
    } else if (datatype == Atom::BIGINT) {
      if (cols == 0)
        memory->destroy(*((bigint **) pdata));
      else if (cols > 0)
        memory->destroy(*((bigint ***) pdata));
      else {
        maxcols = *(mgrow.maxcols[i]);
        memory->destroy(*((bigint ***) pdata));
      }
    }
  }

  destroy_method(&mgrow);
  destroy_method(&mcopy);
  destroy_method(&mcomm);