modernize and fix some memory leaks
This commit is contained in:
@ -18,9 +18,6 @@
|
|||||||
|
|
||||||
#include "fix_mscg.h"
|
#include "fix_mscg.h"
|
||||||
|
|
||||||
#include <cstring>
|
|
||||||
|
|
||||||
#include "mscg.h"
|
|
||||||
#include "atom.h"
|
#include "atom.h"
|
||||||
#include "comm.h"
|
#include "comm.h"
|
||||||
#include "domain.h"
|
#include "domain.h"
|
||||||
@ -35,6 +32,10 @@
|
|||||||
#include "update.h"
|
#include "update.h"
|
||||||
#include "variable.h"
|
#include "variable.h"
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
#include "mscg.h"
|
||||||
|
|
||||||
using namespace LAMMPS_NS;
|
using namespace LAMMPS_NS;
|
||||||
using namespace FixConst;
|
using namespace FixConst;
|
||||||
|
|
||||||
@ -49,8 +50,7 @@ FixMSCG::FixMSCG(LAMMPS *lmp, int narg, char **arg) :
|
|||||||
|
|
||||||
me = comm->me;
|
me = comm->me;
|
||||||
nprocs = comm->nprocs;
|
nprocs = comm->nprocs;
|
||||||
if (nprocs > 1) error->all(FLERR,"Fix mscg does not yet support "
|
if (nprocs > 1) error->all(FLERR,"Fix mscg does not yet support parallel use via MPI");
|
||||||
"parallel use via MPI");
|
|
||||||
|
|
||||||
if (sizeof(tagint) != sizeof(smallint))
|
if (sizeof(tagint) != sizeof(smallint))
|
||||||
error->all(FLERR,"Fix mscg must be used with 32-bit atom IDs");
|
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;
|
name_flag = 1;
|
||||||
for (int i = 0; i < ntypes; i++) {
|
for (int i = 0; i < ntypes; i++) {
|
||||||
iarg += 1;
|
iarg += 1;
|
||||||
std::string str = arg[iarg];
|
delete[] type_names[i];
|
||||||
type_names[i] = strcat(strdup(str.c_str()),"\0");
|
type_names[i] = utils::strdup(arg[iarg]);
|
||||||
}
|
}
|
||||||
iarg += 1;
|
iarg += 1;
|
||||||
} else if (strcmp(arg[iarg],"max") == 0) {
|
} else if (strcmp(arg[iarg],"max") == 0) {
|
||||||
if (iarg+4 > narg) error->all(FLERR,"Illegal fix mscg command");
|
if (iarg+4 > narg) error->all(FLERR,"Illegal fix mscg command");
|
||||||
max_partners_bond = atoi(arg[iarg+1]);
|
max_partners_bond = utils::inumeric(FLERR,arg[iarg+1],false, lmp);
|
||||||
max_partners_angle = atoi(arg[iarg+2]);
|
max_partners_angle = utils::inumeric(FLERR,arg[iarg+2],false, lmp);
|
||||||
max_partners_dihedral = atoi(arg[iarg+3]);
|
max_partners_dihedral = utils::inumeric(FLERR,arg[iarg+3],false, lmp);
|
||||||
iarg += 4;
|
iarg += 4;
|
||||||
} else error->all(FLERR,"Illegal fix mscg command");
|
} else error->all(FLERR,"Illegal fix mscg command");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (name_flag == 0) {
|
if (name_flag == 0) {
|
||||||
for (int i = 0; i < natoms; i++) {
|
for (int i = 0; i < natoms; i++) {
|
||||||
std::string str = std::to_string(i+1);
|
delete[] type_names[i];
|
||||||
type_names[i] = strcat(strdup(str.c_str()),"\0");
|
type_names[i] = utils::strdup(std::to_string(i+1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -114,6 +114,9 @@ FixMSCG::FixMSCG(LAMMPS *lmp, int narg, char **arg) :
|
|||||||
|
|
||||||
FixMSCG::~FixMSCG()
|
FixMSCG::~FixMSCG()
|
||||||
{
|
{
|
||||||
|
int natoms = atom->natoms;
|
||||||
|
for (int i = 0; i < natoms; i++) delete[] type_names[i];
|
||||||
|
delete[] type_names;
|
||||||
memory->destroy(f);
|
memory->destroy(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user