prevent potential memory leak

This commit is contained in:
Axel Kohlmeyer
2023-10-10 13:53:56 -04:00
parent 2b1985f755
commit 07a0333670

View File

@ -27,8 +27,8 @@ using namespace LAMMPS_NS;
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
ComputeMSDChunk::ComputeMSDChunk(LAMMPS *lmp, int narg, char **arg) : ComputeMSDChunk::ComputeMSDChunk(LAMMPS *lmp, int narg, char **arg) :
ComputeChunk(lmp, narg, arg), id_fix(nullptr), massproc(nullptr), masstotal(nullptr), ComputeChunk(lmp, narg, arg), id_fix(nullptr), fix(nullptr), massproc(nullptr),
com(nullptr), comall(nullptr), msd(nullptr) masstotal(nullptr), com(nullptr), comall(nullptr), msd(nullptr)
{ {
if (narg != 4) error->all(FLERR, "Illegal compute msd/chunk command"); if (narg != 4) error->all(FLERR, "Illegal compute msd/chunk command");
@ -196,6 +196,12 @@ void ComputeMSDChunk::compute_array()
void ComputeMSDChunk::allocate() void ComputeMSDChunk::allocate()
{ {
ComputeChunk::allocate(); ComputeChunk::allocate();
memory->destroy(massproc);
memory->destroy(masstotal);
memory->destroy(com);
memory->destroy(comall);
memory->destroy(msd);
memory->create(massproc, nchunk, "msd/chunk:massproc"); memory->create(massproc, nchunk, "msd/chunk:massproc");
memory->create(masstotal, nchunk, "msd/chunk:masstotal"); memory->create(masstotal, nchunk, "msd/chunk:masstotal");
memory->create(com, nchunk, 3, "msd/chunk:com"); memory->create(com, nchunk, 3, "msd/chunk:com");