From 19d6227220a4af9c8be28dd04f91e5d249eb43c6 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 20 Aug 2024 09:19:58 -0400 Subject: [PATCH] plug memory leaks in testers --- src/FEP/pair_morse_soft.cpp | 2 +- src/FEP/pair_morse_soft.h | 2 +- unittest/c-library/test_library_open.cpp | 1 + unittest/fortran/wrap_get_thermo.cpp | 17 +++++++++++++---- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/FEP/pair_morse_soft.cpp b/src/FEP/pair_morse_soft.cpp index d9be7e136d..e2cb92e303 100644 --- a/src/FEP/pair_morse_soft.cpp +++ b/src/FEP/pair_morse_soft.cpp @@ -35,7 +35,7 @@ using namespace MathSpecial; PairMorseSoft::~PairMorseSoft() { - if (allocated) { memory->destroy(lambda); } + if (allocated) memory->destroy(lambda); } /* ---------------------------------------------------------------------- */ diff --git a/src/FEP/pair_morse_soft.h b/src/FEP/pair_morse_soft.h index 0c12fbafde..9f4dcbd024 100644 --- a/src/FEP/pair_morse_soft.h +++ b/src/FEP/pair_morse_soft.h @@ -30,7 +30,7 @@ namespace LAMMPS_NS { class PairMorseSoft : public PairMorse { public: PairMorseSoft(class LAMMPS *lmp) : - PairMorse(lmp), lambda(nullptr), nlambda(0), shift_range(1.0){}; + PairMorse(lmp), lambda(nullptr), nlambda(0), shift_range(1.0) {}; ~PairMorseSoft() override; void compute(int, int) override; diff --git a/unittest/c-library/test_library_open.cpp b/unittest/c-library/test_library_open.cpp index 6f2ea9ac33..61ef080b9a 100644 --- a/unittest/c-library/test_library_open.cpp +++ b/unittest/c-library/test_library_open.cpp @@ -256,4 +256,5 @@ TEST(lammps_open_no_mpi, lammps_error) lammps_error(handle, 0, "test_warning"); output = ::testing::internal::GetCapturedStdout(); EXPECT_THAT(output, HasSubstr("WARNING: test_warning")); + lammps_close(handle); } diff --git a/unittest/fortran/wrap_get_thermo.cpp b/unittest/fortran/wrap_get_thermo.cpp index e18697ba9b..3a2b810858 100644 --- a/unittest/fortran/wrap_get_thermo.cpp +++ b/unittest/fortran/wrap_get_thermo.cpp @@ -85,10 +85,19 @@ TEST_F(LAMMPS_thermo, last_thermo) f_lammps_last_thermo_setup(); EXPECT_EQ(f_lammps_last_thermo_step(), 15); EXPECT_EQ(f_lammps_last_thermo_num(), 6); - EXPECT_STREQ(f_lammps_last_thermo_string(1), "Step"); - EXPECT_STREQ(f_lammps_last_thermo_string(2), "Temp"); - EXPECT_STREQ(f_lammps_last_thermo_string(3), "E_pair"); - EXPECT_STREQ(f_lammps_last_thermo_string(6), "Press"); + char *thermostr; + thermostr = (char *)f_lammps_last_thermo_string(1); + EXPECT_STREQ(thermostr, "Step"); + free(thermostr); + thermostr = (char *)f_lammps_last_thermo_string(2); + EXPECT_STREQ(thermostr, "Temp"); + free(thermostr); + thermostr = (char *)f_lammps_last_thermo_string(3); + EXPECT_STREQ(thermostr, "E_pair"); + free(thermostr); + thermostr = (char *)f_lammps_last_thermo_string(6); + EXPECT_STREQ(thermostr, "Press"); + free(thermostr); #if defined(LAMMPS_SMALLSMALL) EXPECT_EQ(f_lammps_last_thermo_type(1), multitype::LAMMPS_INT); #else