Index: lib/sanitizer_common/tests/sanitizer_allocator_test.cc =================================================================== --- lib/sanitizer_common/tests/sanitizer_allocator_test.cc +++ lib/sanitizer_common/tests/sanitizer_allocator_test.cc @@ -615,6 +615,24 @@ std::shuffle(allocated.begin(), allocated.end(), r); + // Test ForEachChunk(...) + { + std::set reported_chunks; + a->ForEachChunk( + [](uptr chunk, void *arg) { + auto reported_chunks_ptr = + reinterpret_cast *>(arg); + auto pair = + reported_chunks_ptr->insert(reinterpret_cast(chunk)); + // Check chunk is never reported more than once. + ASSERT_TRUE(pair.second); + }, + reinterpret_cast(&reported_chunks)); + for (const auto &allocated_ptr : allocated) { + ASSERT_NE(reported_chunks.find(allocated_ptr), reported_chunks.end()); + } + } + for (uptr i = 0; i < kNumAllocs; i++) { void *x = allocated[i]; uptr *meta = reinterpret_cast(a->GetMetaData(x));