Skip to content

Commit

Permalink
Use a shared pointer to bool to check if destructor ran (#1657)
Browse files Browse the repository at this point in the history
Destructor may run after the flag has been deleted. Not even Valgrind
caught this.
  • Loading branch information
franzpoeschel committed Aug 1, 2024
1 parent 4f83a7e commit 443fdef
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions test/SerialIOTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>(false);
UniquePtrWithLambda<int32_t> 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());
{
Expand All @@ -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();
Expand Down

0 comments on commit 443fdef

Please sign in to comment.