From f2aacca803c40b13eabefa1530d77e74e710fcec Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 21 Sep 2021 22:03:38 -0400 Subject: [PATCH] modernize and fix some memory leaks --- src/MSCG/fix_mscg.cpp | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/MSCG/fix_mscg.cpp b/src/MSCG/fix_mscg.cpp index 0d420cace8..d41299e3b2 100644 --- a/src/MSCG/fix_mscg.cpp +++ b/src/MSCG/fix_mscg.cpp @@ -18,9 +18,6 @@ #include "fix_mscg.h" -#include - -#include "mscg.h" #include "atom.h" #include "comm.h" #include "domain.h" @@ -35,6 +32,10 @@ #include "update.h" #include "variable.h" +#include + +#include "mscg.h" + using namespace LAMMPS_NS; using namespace FixConst; @@ -49,8 +50,7 @@ FixMSCG::FixMSCG(LAMMPS *lmp, int narg, char **arg) : me = comm->me; nprocs = comm->nprocs; - if (nprocs > 1) error->all(FLERR,"Fix mscg does not yet support " - "parallel use via MPI"); + if (nprocs > 1) error->all(FLERR,"Fix mscg does not yet support parallel use via MPI"); if (sizeof(tagint) != sizeof(smallint)) error->all(FLERR,"Fix mscg must be used with 32-bit atom IDs"); @@ -89,23 +89,23 @@ FixMSCG::FixMSCG(LAMMPS *lmp, int narg, char **arg) : name_flag = 1; for (int i = 0; i < ntypes; i++) { iarg += 1; - std::string str = arg[iarg]; - type_names[i] = strcat(strdup(str.c_str()),"\0"); + delete[] type_names[i]; + type_names[i] = utils::strdup(arg[iarg]); } iarg += 1; } else if (strcmp(arg[iarg],"max") == 0) { if (iarg+4 > narg) error->all(FLERR,"Illegal fix mscg command"); - max_partners_bond = atoi(arg[iarg+1]); - max_partners_angle = atoi(arg[iarg+2]); - max_partners_dihedral = atoi(arg[iarg+3]); + max_partners_bond = utils::inumeric(FLERR,arg[iarg+1],false, lmp); + max_partners_angle = utils::inumeric(FLERR,arg[iarg+2],false, lmp); + max_partners_dihedral = utils::inumeric(FLERR,arg[iarg+3],false, lmp); iarg += 4; } else error->all(FLERR,"Illegal fix mscg command"); } if (name_flag == 0) { for (int i = 0; i < natoms; i++) { - std::string str = std::to_string(i+1); - type_names[i] = strcat(strdup(str.c_str()),"\0"); + delete[] type_names[i]; + type_names[i] = utils::strdup(std::to_string(i+1)); } } } @@ -114,6 +114,9 @@ FixMSCG::FixMSCG(LAMMPS *lmp, int narg, char **arg) : FixMSCG::~FixMSCG() { + int natoms = atom->natoms; + for (int i = 0; i < natoms; i++) delete[] type_names[i]; + delete[] type_names; memory->destroy(f); }