Skip to content

Commit 8a8091c

Browse files
committed
Use a shared pointer to bool to check if destructor ran
Destructor may run after the flag has been deleted. Not even Valgrind caught this.
1 parent cfe7aae commit 8a8091c

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

test/SerialIOTest.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -4286,11 +4286,11 @@ void adios2_bp5_flush(std::string const &cfg, FlushDuringStep flushDuringStep)
42864286
REQUIRE(currentSize <= 4096);
42874287
}
42884288

4289-
bool has_been_deleted = false;
4289+
auto has_been_deleted = std::make_shared<bool>(false);
42904290
UniquePtrWithLambda<int32_t> copied_as_unique(
4291-
new int[size], [&has_been_deleted](int const *ptr) {
4291+
new int[size], [has_been_deleted](int const *ptr) {
42924292
delete[] ptr;
4293-
has_been_deleted = true;
4293+
*has_been_deleted = true;
42944294
});
42954295
std::copy_n(data.data(), size, copied_as_unique.get());
42964296
{
@@ -4308,13 +4308,13 @@ void adios2_bp5_flush(std::string const &cfg, FlushDuringStep flushDuringStep)
43084308
{
43094309
// should now be roughly within 1% of 16Mb
43104310
REQUIRE(std::abs(1 - double(currentSize) / (16 * size)) <= 0.01);
4311-
REQUIRE(has_been_deleted);
4311+
REQUIRE(*has_been_deleted);
43124312
}
43134313
else
43144314
{
43154315
// should be roughly zero
43164316
REQUIRE(currentSize <= 4096);
4317-
REQUIRE(!has_been_deleted);
4317+
REQUIRE(!*has_been_deleted);
43184318
}
43194319
}
43204320
auto currentSize = getsize();

0 commit comments

Comments
 (0)