Skip to content

Commit

Permalink
Fix dangling pointer in SolverTest.SettersGettersWithSetup (#2556)
Browse files Browse the repository at this point in the history
Fixes a dangling pointer issue in SolverTest.SettersGettersWithSetup.
The SUNContext was destroyed before the associated AmiVectors which resulted in invalid reads.
  • Loading branch information
dweindl committed Oct 20, 2024
1 parent 40b496f commit fbe3840
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
2 changes: 1 addition & 1 deletion scripts/run-valgrind-cpp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ set -eou pipefail
# run tests
cd "${AMICI_PATH}/build/"
VALGRIND_OPTS="--leak-check=full --error-exitcode=1 --trace-children=yes --show-leak-kinds=definite"
valgrind ${VALGRIND_OPTS} ctest
CTEST_OUTPUT_ON_FAILURE=1 valgrind ${VALGRIND_OPTS} ctest
5 changes: 2 additions & 3 deletions tests/cpp/unittests/testMisc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,10 +360,9 @@ TEST_F(SolverTest, SettersGettersWithSetup)
ASSERT_EQ(static_cast<int>(solver.getSensitivityMethod()),
static_cast<int>(sensi_meth));

sundials::Context sunctx;
auto rdata = std::make_unique<ReturnData>(solver, testModel);
AmiVector x(nx, sunctx), dx(nx, sunctx);
AmiVectorArray sx(nx, 1, sunctx), sdx(nx, 1, sunctx);
AmiVector x(nx, solver.getSunContext()), dx(nx, solver.getSunContext());
AmiVectorArray sx(nx, 1, solver.getSunContext()), sdx(nx, 1, solver.getSunContext());

testModel.setInitialStates(std::vector<realtype>{ 0 });

Expand Down

0 comments on commit fbe3840

Please sign in to comment.