From a4c8650d2a603177b2be76b2a0779ea3f797e84c Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 20 Jun 2021 21:29:08 -0400 Subject: [PATCH] plug memory leaks in USER-PACE --- src/USER-PACE/pair_pace.cpp | 8 ++++---- .../force-styles/tests/manybody-pair-pace_product.yaml | 1 - .../force-styles/tests/manybody-pair-pace_recursive.yaml | 1 - 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/USER-PACE/pair_pace.cpp b/src/USER-PACE/pair_pace.cpp index 952fd07a1a..fba622546e 100644 --- a/src/USER-PACE/pair_pace.cpp +++ b/src/USER-PACE/pair_pace.cpp @@ -50,6 +50,8 @@ Copyright 2021 Yury Lysogorskiy^1, Cas van der Oord^2, Anton Bochkarev^1, namespace LAMMPS_NS { struct ACEImpl { + ACEImpl() : basis_set(nullptr), ace(nullptr){} + ~ACEImpl() {delete basis_set; delete ace;} ACECTildeBasisSet *basis_set; ACERecursiveEvaluator *ace; }; @@ -93,8 +95,6 @@ PairPACE::PairPACE(LAMMPS *lmp) : Pair(lmp) { manybody_flag = 1; aceimpl = new ACEImpl; - aceimpl->ace = nullptr; - aceimpl->basis_set = nullptr; recursive = false; scale = nullptr; @@ -107,8 +107,6 @@ PairPACE::PairPACE(LAMMPS *lmp) : Pair(lmp) { PairPACE::~PairPACE() { if (copymode) return; - delete aceimpl->basis_set; - delete aceimpl->ace; delete aceimpl; if (allocated) { @@ -297,6 +295,7 @@ void PairPACE::coeff(int narg, char **arg) { char **elemtypes = &arg[3]; //load potential file + delete aceimpl->basis_set; aceimpl->basis_set = new ACECTildeBasisSet(); if (comm->me == 0) utils::logmesg(lmp,"Loading {}\n", potential_file_name); @@ -316,6 +315,7 @@ void PairPACE::coeff(int narg, char **arg) { // map[i] = which element the Ith atom type is, -1 if not mapped // map[0] is not used + delete aceimpl->ace; aceimpl->ace = new ACERecursiveEvaluator(); aceimpl->ace->set_recursive(recursive); aceimpl->ace->element_type_mapping.init(atom->ntypes + 1); diff --git a/unittest/force-styles/tests/manybody-pair-pace_product.yaml b/unittest/force-styles/tests/manybody-pair-pace_product.yaml index 21c37c49be..0911e1d81d 100644 --- a/unittest/force-styles/tests/manybody-pair-pace_product.yaml +++ b/unittest/force-styles/tests/manybody-pair-pace_product.yaml @@ -2,7 +2,6 @@ lammps_version: 10 Mar 2021 date_generated: Wed Apr 7 19:29:52 2021 epsilon: 5e-13 -skip_tests: prerequisites: ! | pair pace pre_commands: ! | diff --git a/unittest/force-styles/tests/manybody-pair-pace_recursive.yaml b/unittest/force-styles/tests/manybody-pair-pace_recursive.yaml index 43b52a5391..eef7509606 100644 --- a/unittest/force-styles/tests/manybody-pair-pace_recursive.yaml +++ b/unittest/force-styles/tests/manybody-pair-pace_recursive.yaml @@ -2,7 +2,6 @@ lammps_version: 10 Mar 2021 date_generated: Wed Apr 7 19:30:07 2021 epsilon: 5e-13 -skip_tests: prerequisites: ! | pair pace pre_commands: ! |