diff --git a/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp b/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp index a2461c53cd950..deccccf4f1f6a 100644 --- a/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp +++ b/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp @@ -679,3 +679,23 @@ SCUDO_TYPED_TEST(ScudoCombinedTest, DisableMemInit) { Allocator->setOption(scudo::Option::ThreadDisableMemInit, 0); } + +SCUDO_TYPED_TEST(ScudoCombinedTest, ReallocateInPlaceStress) { + auto *Allocator = this->Allocator.get(); + + // Regression test: make realloc-in-place happen at the very right end of a + // mapped region. + constexpr int nPtrs = 10000; + for (int i = 1; i < 32; ++i) { + scudo::uptr Size = 16 * i - 1; + std::vector Ptrs; + for (int i = 0; i < nPtrs; ++i) { + void *P = Allocator->allocate(Size, Origin); + P = Allocator->reallocate(P, Size + 1); + Ptrs.push_back(P); + } + + for (int i = 0; i < nPtrs; ++i) + Allocator->deallocate(Ptrs[i], Origin); + } +}