avoid memory leaks from extracting scalar data from fixes

This commit is contained in:
Axel Kohlmeyer
2024-08-02 18:17:01 -04:00
parent b41b2c9bfc
commit 0367f3ed07

View File

@ -547,13 +547,22 @@ TEST_F(LibraryProperties, neighlist)
lammps_command(lmp, "run 0 post no"); lammps_command(lmp, "run 0 post no");
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
int nhisto = void *ptr = lammps_extract_fix(lmp, "dist", LMP_STYLE_GLOBAL, LMP_TYPE_VECTOR, 0, 0);
*(double *)lammps_extract_fix(lmp, "dist", LMP_STYLE_GLOBAL, LMP_TYPE_VECTOR, 0, 0); int nhisto = *(double *)ptr;
int nskip = *(double *)lammps_extract_fix(lmp, "dist", LMP_STYLE_GLOBAL, LMP_TYPE_VECTOR, 1, 0); lammps_free(ptr);
double minval =
*(double *)lammps_extract_fix(lmp, "dist", LMP_STYLE_GLOBAL, LMP_TYPE_VECTOR, 2, 0); ptr = lammps_extract_fix(lmp, "dist", LMP_STYLE_GLOBAL, LMP_TYPE_VECTOR, 1, 0);
double maxval = int nskip = *(double *)ptr;
*(double *)lammps_extract_fix(lmp, "dist", LMP_STYLE_GLOBAL, LMP_TYPE_VECTOR, 3, 0); lammps_free(ptr);
ptr = lammps_extract_fix(lmp, "dist", LMP_STYLE_GLOBAL, LMP_TYPE_VECTOR, 2, 0);
double minval = *(double *)ptr;
lammps_free(ptr);
ptr = lammps_extract_fix(lmp, "dist", LMP_STYLE_GLOBAL, LMP_TYPE_VECTOR, 3, 0);
double maxval = *(double *)ptr;
lammps_free(ptr);
// 21 pair distances counted, none skipped, smallest 1.0, largest 2.1 // 21 pair distances counted, none skipped, smallest 1.0, largest 2.1
EXPECT_EQ(nhisto, 21); EXPECT_EQ(nhisto, 21);
EXPECT_EQ(nskip, 0); EXPECT_EQ(nskip, 0);