diff --git a/compiler-rt/lib/scudo/standalone/tests/wrappers_c_test.cpp b/compiler-rt/lib/scudo/standalone/tests/wrappers_c_test.cpp --- a/compiler-rt/lib/scudo/standalone/tests/wrappers_c_test.cpp +++ b/compiler-rt/lib/scudo/standalone/tests/wrappers_c_test.cpp @@ -9,12 +9,14 @@ #include "memtag.h" #include "scudo/interface.h" #include "tests/scudo_unit_test.h" +#include "common.h" #include #include #include #include #include +#include #ifndef __GLIBC_PREREQ #define __GLIBC_PREREQ(x, y) 0 @@ -100,15 +102,22 @@ } TEST(ScudoWrappersCTest, SmallAlign) { - void *P; - for (size_t Size = 1; Size <= 0x10000; Size <<= 1) { - for (size_t Align = 1; Align <= 0x10000; Align <<= 1) { + //allocating pointers to test if created blocks are correctly aligned from 1 to 0x10000 with left shifts + constexpr size_t MaxSize = 0x10000; + std::vector ptrs; + //reserving space to keep track of created pointers to prevent memory leak + ptrs.reserve((scudo::getLeastSignificantSetBitIndex(MaxSize) + 1) * (scudo::getLeastSignificantSetBitIndex(MaxSize) + 1) * 3); + for (size_t Size = 1; Size <= MaxSize; Size <<= 1) { + for (size_t Align = 1; Align <= MaxSize; Align <<= 1) { for (size_t Count = 0; Count < 3; ++Count) { - P = memalign(Align, Size); + void *P = memalign(Align, Size); EXPECT_TRUE(reinterpret_cast(P) % Align == 0); + ptrs.push_back(P); } } } + for(void *ptr : ptrs) + free(ptr); } TEST(ScudoWrappersCTest, Memalign) {