From da1bbec0be814f83cce805c78c964822f232defa Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 29 Jan 2025 23:32:52 -0500 Subject: [PATCH] set lmp pointer to NULL after delete to avoid using it or deleting it a second time --- unittest/force-styles/test_angle_style.cpp | 3 ++- unittest/force-styles/test_bond_style.cpp | 3 ++- unittest/force-styles/test_dihedral_style.cpp | 3 ++- unittest/force-styles/test_fix_timestep.cpp | 3 ++- unittest/force-styles/test_improper_style.cpp | 3 ++- unittest/force-styles/test_pair_style.cpp | 3 ++- 6 files changed, 12 insertions(+), 6 deletions(-) diff --git a/unittest/force-styles/test_angle_style.cpp b/unittest/force-styles/test_angle_style.cpp index 80601d3632..e24e5401df 100644 --- a/unittest/force-styles/test_angle_style.cpp +++ b/unittest/force-styles/test_angle_style.cpp @@ -53,12 +53,13 @@ using ::testing::StartsWith; using namespace LAMMPS_NS; -void cleanup_lammps(LAMMPS *lmp, const TestConfig &cfg) +void cleanup_lammps(LAMMPS *&lmp, const TestConfig &cfg) { platform::unlink(cfg.basename + ".restart"); platform::unlink(cfg.basename + ".data"); platform::unlink(cfg.basename + "-coeffs.in"); delete lmp; + lmp = nullptr; } LAMMPS *init_lammps(LAMMPS::argv &args, const TestConfig &cfg, const bool newton) diff --git a/unittest/force-styles/test_bond_style.cpp b/unittest/force-styles/test_bond_style.cpp index 6c680feaa3..660435cf49 100644 --- a/unittest/force-styles/test_bond_style.cpp +++ b/unittest/force-styles/test_bond_style.cpp @@ -53,12 +53,13 @@ using ::testing::StartsWith; using namespace LAMMPS_NS; -void cleanup_lammps(LAMMPS *lmp, const TestConfig &cfg) +void cleanup_lammps(LAMMPS *&lmp, const TestConfig &cfg) { platform::unlink(cfg.basename + ".restart"); platform::unlink(cfg.basename + ".data"); platform::unlink(cfg.basename + "-coeffs.in"); delete lmp; + lmp = nullptr; } LAMMPS *init_lammps(LAMMPS::argv &args, const TestConfig &cfg, const bool newton) diff --git a/unittest/force-styles/test_dihedral_style.cpp b/unittest/force-styles/test_dihedral_style.cpp index ed9ceff1e8..5d0bd86d2b 100644 --- a/unittest/force-styles/test_dihedral_style.cpp +++ b/unittest/force-styles/test_dihedral_style.cpp @@ -53,12 +53,13 @@ using ::testing::StartsWith; using namespace LAMMPS_NS; -void cleanup_lammps(LAMMPS *lmp, const TestConfig &cfg) +void cleanup_lammps(LAMMPS *&lmp, const TestConfig &cfg) { platform::unlink(cfg.basename + ".restart"); platform::unlink(cfg.basename + ".data"); platform::unlink(cfg.basename + "-coeffs.in"); delete lmp; + lmp = nullptr; } LAMMPS *init_lammps(LAMMPS::argv &args, const TestConfig &cfg, const bool newton) diff --git a/unittest/force-styles/test_fix_timestep.cpp b/unittest/force-styles/test_fix_timestep.cpp index f175e1cd64..b952a3c045 100644 --- a/unittest/force-styles/test_fix_timestep.cpp +++ b/unittest/force-styles/test_fix_timestep.cpp @@ -56,10 +56,11 @@ using ::testing::StartsWith; using namespace LAMMPS_NS; -void cleanup_lammps(LAMMPS *lmp, const TestConfig &cfg) +void cleanup_lammps(LAMMPS *&lmp, const TestConfig &cfg) { platform::unlink(cfg.basename + ".restart"); delete lmp; + lmp = nullptr; } LAMMPS *init_lammps(LAMMPS::argv &args, const TestConfig &cfg, const bool use_respa) diff --git a/unittest/force-styles/test_improper_style.cpp b/unittest/force-styles/test_improper_style.cpp index 5b38ad38c4..e272033e85 100644 --- a/unittest/force-styles/test_improper_style.cpp +++ b/unittest/force-styles/test_improper_style.cpp @@ -53,12 +53,13 @@ using ::testing::StartsWith; using namespace LAMMPS_NS; -void cleanup_lammps(LAMMPS *lmp, const TestConfig &cfg) +void cleanup_lammps(LAMMPS *&lmp, const TestConfig &cfg) { platform::unlink(cfg.basename + ".restart"); platform::unlink(cfg.basename + ".data"); platform::unlink(cfg.basename + "-coeffs.in"); delete lmp; + lmp = nullptr; } LAMMPS *init_lammps(LAMMPS::argv &args, const TestConfig &cfg, const bool newton) diff --git a/unittest/force-styles/test_pair_style.cpp b/unittest/force-styles/test_pair_style.cpp index 90ebe09513..6dabeab7a4 100644 --- a/unittest/force-styles/test_pair_style.cpp +++ b/unittest/force-styles/test_pair_style.cpp @@ -54,12 +54,13 @@ using ::testing::StartsWith; using namespace LAMMPS_NS; -void cleanup_lammps(LAMMPS *lmp, const TestConfig &cfg) +void cleanup_lammps(LAMMPS *&lmp, const TestConfig &cfg) { platform::unlink(cfg.basename + ".restart"); platform::unlink(cfg.basename + ".data"); platform::unlink(cfg.basename + "-coeffs.in"); delete lmp; + lmp = nullptr; } LAMMPS *init_lammps(LAMMPS::argv &args, const TestConfig &cfg, const bool newton)