Skip to content

Commit

Permalink
Fix memory overflow bug in library.cpp
Browse files Browse the repository at this point in the history
int *list,*mark, and class RanPark *random need to be released after allocations
  • Loading branch information
shelllbw authored Dec 13, 2021
1 parent c555061 commit d4d6108
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions interfaceToLammps/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,8 @@ void lammps_delete_particle(void *ptr, int* deleteList, int nDelete)
int i,j,m,iwhichglobal,iwhichlocal;
int ndel,ndeltopo[4];
int *list,*mark;

int del_flag = 0;

// grow list and mark arrays if necessary

int nmax = 0;
Expand All @@ -510,6 +511,7 @@ void lammps_delete_particle(void *ptr, int* deleteList, int nDelete)
nmax = lammps->atom->nmax;
lammps->memory->create(list,nmax,"evaporate:list");
lammps->memory->create(mark,nmax,"evaporate:mark");
del_flag = 1;
}

// ncount = # of deletable atoms in region that I own
Expand Down Expand Up @@ -611,5 +613,9 @@ void lammps_delete_particle(void *ptr, int* deleteList, int nDelete)

// ndeleted += ndel;
// next_reneighbor = update->ntimestep + nevery;
// delete [] random;
delete random;
if (del_flag) {
lammps->memory->destroy(list);
lammps->memory->destroy(mark);
}
}

0 comments on commit d4d6108

Please sign in to comment.