[sanitizer] Fix the region overflow condition in SanitizerAllocator64::PopulateFreeList().

llvm-svn: 182002
This commit is contained in:
Sergey Matveev 2013-05-16 12:58:34 +00:00
parent 997af66087
commit efb6172cb3
2 changed files with 30 additions and 1 deletions

View File

@ -535,7 +535,7 @@ class SizeClassAllocator64 {
region->mapped_meta += map_size;
}
CHECK_LE(region->allocated_meta, region->mapped_meta);
if (region->allocated_user + region->allocated_meta > kRegionSize) {
if (region->mapped_user + region->mapped_meta > kRegionSize) {
Printf("%s: Out of memory. Dying. ", SanitizerToolName);
Printf("The process has exhausted %zuMB for size class %zu.\n",
kRegionSize / 1024 / 1024, size);

View File

@ -701,4 +701,33 @@ TEST(SanitizerCommon, LargeMmapAllocatorIteration) {
}
}
#if SANITIZER_WORDSIZE == 64
// Regression test for out-of-memory condition in PopulateFreeList().
TEST(SanitizerCommon, SizeClassAllocator64PopulateFreeListOOM) {
// In a world where regions are small and chunks are huge...
typedef SizeClassMap<63, 128, 16> SpecialSizeClassMap;
typedef SizeClassAllocator64<kAllocatorSpace, kAllocatorSize, 0,
SpecialSizeClassMap> SpecialAllocator64;
const uptr kRegionSize =
kAllocatorSize / SpecialSizeClassMap::kNumClassesRounded;
SpecialAllocator64 *a = new SpecialAllocator64;
a->Init();
SizeClassAllocatorLocalCache<SpecialAllocator64> cache;
memset(&cache, 0, sizeof(cache));
cache.Init(0);
// ...one man is on a mission to overflow a region with a series of
// successive allocations.
const uptr kClassID = 107;
const uptr kAllocationSize = DefaultSizeClassMap::Size(kClassID);
ASSERT_LT(2 * kAllocationSize, kRegionSize);
ASSERT_GT(3 * kAllocationSize, kRegionSize);
cache.Allocate(a, kClassID);
EXPECT_DEATH(cache.Allocate(a, kClassID) && cache.Allocate(a, kClassID),
"The process has exhausted");
a->TestOnlyUnmap();
delete a;
}
#endif
#endif // #if TSAN_DEBUG==0