Skip to content
Snippets Groups Projects
Commit 4314299b authored by Axel Kohlmeyer's avatar Axel Kohlmeyer
Browse files

harden fix shear/history against use-after-delete and from incorrect use of reverse communication

parent 3bb3c1a4
No related branches found
No related tags found
No related merge requests found
...@@ -29,13 +29,13 @@ ...@@ -29,13 +29,13 @@
using namespace LAMMPS_NS; using namespace LAMMPS_NS;
using namespace FixConst; using namespace FixConst;
enum{NPARTNER,PERPARTNER}; enum{DEFAULT,NPARTNER,PERPARTNER};
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
FixShearHistory::FixShearHistory(LAMMPS *lmp, int narg, char **arg) : FixShearHistory::FixShearHistory(LAMMPS *lmp, int narg, char **arg) :
Fix(lmp, narg, arg), Fix(lmp, narg, arg),
npartner(NULL), partner(NULL), shearpartner(NULL), ipage(NULL), dpage(NULL) npartner(NULL), partner(NULL), shearpartner(NULL), pair(NULL), ipage(NULL), dpage(NULL)
{ {
if (narg != 4) error->all(FLERR,"Illegal fix SHEAR_HISTORY commmand"); if (narg != 4) error->all(FLERR,"Illegal fix SHEAR_HISTORY commmand");
...@@ -71,6 +71,7 @@ FixShearHistory::FixShearHistory(LAMMPS *lmp, int narg, char **arg) : ...@@ -71,6 +71,7 @@ FixShearHistory::FixShearHistory(LAMMPS *lmp, int narg, char **arg) :
maxtouch = 0; maxtouch = 0;
nlocal_neigh = nall_neigh = 0; nlocal_neigh = nall_neigh = 0;
commflag = DEFAULT;
} }
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
...@@ -87,6 +88,14 @@ FixShearHistory::~FixShearHistory() ...@@ -87,6 +88,14 @@ FixShearHistory::~FixShearHistory()
memory->destroy(npartner); memory->destroy(npartner);
memory->sfree(partner); memory->sfree(partner);
memory->sfree(shearpartner); memory->sfree(shearpartner);
// to better detect use-after-delete errors
pair = NULL;
npartner = NULL;
partner = NULL;
shearpartner = NULL;
delete [] ipage; delete [] ipage;
delete [] dpage; delete [] dpage;
} }
...@@ -609,7 +618,7 @@ int FixShearHistory::pack_reverse_comm(int n, int first, double *buf) ...@@ -609,7 +618,7 @@ int FixShearHistory::pack_reverse_comm(int n, int first, double *buf)
m += dnum; m += dnum;
} }
} }
} } else error->all(FLERR,"Unsupported comm mode in shear history");
return m; return m;
} }
...@@ -640,7 +649,7 @@ void FixShearHistory::unpack_reverse_comm(int n, int *list, double *buf) ...@@ -640,7 +649,7 @@ void FixShearHistory::unpack_reverse_comm(int n, int *list, double *buf)
m += dnum; m += dnum;
} }
} }
} } else error->all(FLERR,"Unsupported comm mode in shear history");
} }
/* ---------------------------------------------------------------------- /* ----------------------------------------------------------------------
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment