From 443fdef7d369b12b2dcc727db5ffaa9ccc11c815 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franz=20P=C3=B6schel?= Date: Thu, 1 Aug 2024 17:25:39 +0200 Subject: [PATCH] Use a shared pointer to bool to check if destructor ran (#1657) Destructor may run after the flag has been deleted. Not even Valgrind caught this. --- test/SerialIOTest.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/SerialIOTest.cpp b/test/SerialIOTest.cpp index 92675110aa..7323a32582 100644 --- a/test/SerialIOTest.cpp +++ b/test/SerialIOTest.cpp @@ -4286,11 +4286,11 @@ void adios2_bp5_flush(std::string const &cfg, FlushDuringStep flushDuringStep) REQUIRE(currentSize <= 4096); } - bool has_been_deleted = false; + auto has_been_deleted = std::make_shared(false); UniquePtrWithLambda copied_as_unique( - new int[size], [&has_been_deleted](int const *ptr) { + new int[size], [has_been_deleted](int const *ptr) { delete[] ptr; - has_been_deleted = true; + *has_been_deleted = true; }); std::copy_n(data.data(), size, copied_as_unique.get()); { @@ -4308,13 +4308,13 @@ void adios2_bp5_flush(std::string const &cfg, FlushDuringStep flushDuringStep) { // should now be roughly within 1% of 16Mb REQUIRE(std::abs(1 - double(currentSize) / (16 * size)) <= 0.01); - REQUIRE(has_been_deleted); + REQUIRE(*has_been_deleted); } else { // should be roughly zero REQUIRE(currentSize <= 4096); - REQUIRE(!has_been_deleted); + REQUIRE(!*has_been_deleted); } } auto currentSize = getsize();