fix small memory leak in pair style hybrid when reading restarts

This commit is contained in:
Axel Kohlmeyer 2019-03-22 05:41:32 -04:00
parent 8916aeb36d
commit 75d63df4e0
No known key found for this signature in database
GPG Key ID: D9B44E93BF0C375A
1 changed files with 19 additions and 6 deletions

View File

@ -45,7 +45,7 @@ PairHybrid::PairHybrid(LAMMPS *lmp) : Pair(lmp),
PairHybrid::~PairHybrid()
{
if (nstyles) {
if (nstyles > 0) {
for (int m = 0; m < nstyles; m++) {
delete styles[m];
delete [] keywords[m];
@ -243,11 +243,18 @@ void PairHybrid::settings(int narg, char **arg)
// delete old lists, since cannot just change settings
if (nstyles) {
for (int m = 0; m < nstyles; m++) delete styles[m];
delete [] styles;
for (int m = 0; m < nstyles; m++) delete [] keywords[m];
delete [] keywords;
if (nstyles > 0) {
for (int m = 0; m < nstyles; m++) {
delete styles[m];
delete [] keywords[m];
if (special_lj[m]) delete [] special_lj[m];
if (special_coul[m]) delete [] special_coul[m];
}
delete[] styles;
delete[] keywords;
delete[] multiple;
delete[] special_lj;
delete[] special_coul;
}
if (allocated) {
@ -670,6 +677,12 @@ void PairHybrid::read_restart(FILE *fp)
// allocate list of sub-styles
delete[] styles;
delete[] keywords;
delete[] multiple;
delete[] special_lj;
delete[] special_coul;
styles = new Pair*[nstyles];
keywords = new char*[nstyles];
multiple = new int[nstyles];