From db469b5cfdb34a6d950a4e9a9e4d8ef2b5b8f5c2 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 17 Jun 2020 01:24:36 -0400 Subject: [PATCH] plug memory leak in AtomVec classes --- src/atom_vec.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/atom_vec.cpp b/src/atom_vec.cpp index 708fedd15e..03b70fc54c 100644 --- a/src/atom_vec.cpp +++ b/src/atom_vec.cpp @@ -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);