Fix mmap region iteration while no regions are recorded.

If no mmap regions are recorded, iteration failed since the RegionSet
(std::set) object is not initialized.

Original CL https://codereview.chromium.org/14769008

Reviewed-on: https://chromium-review.googlesource.com/c/1130807
This commit is contained in:
Gabriel Marin 2018-10-04 22:52:35 +00:00 committed by Aliaksey Kandratsenka
parent acdcacc28f
commit 1de76671d4
2 changed files with 16 additions and 6 deletions

19
src/memory_region_map.cc Executable file → Normal file
View File

@ -234,6 +234,9 @@ void MemoryRegionMap::Init(int max_stack_depth, bool use_buckets) {
memset(bucket_table_, 0, table_bytes);
num_buckets_ = 0;
}
if (regions_ == NULL) { // init regions_
InitRegionSetLocked();
}
Unlock();
RAW_VLOG(10, "MemoryRegionMap Init done");
}
@ -536,6 +539,15 @@ void MemoryRegionMap::RestoreSavedBucketsLocked() {
}
}
inline void MemoryRegionMap::InitRegionSetLocked() {
RAW_VLOG(12, "Initializing region set");
regions_ = regions_rep.region_set();
recursive_insert = true;
new (regions_) RegionSet();
HandleSavedRegionsLocked(&DoInsertRegionLocked);
recursive_insert = false;
}
inline void MemoryRegionMap::InsertRegionLocked(const Region& region) {
RAW_CHECK(LockIsHeld(), "should be held (by this thread)");
// We can be called recursively, because RegionSet constructor
@ -556,12 +568,7 @@ inline void MemoryRegionMap::InsertRegionLocked(const Region& region) {
saved_regions[saved_regions_count++] = region;
} else { // not a recusrive call
if (regions_ == NULL) { // init regions_
RAW_VLOG(12, "Initializing region set");
regions_ = regions_rep.region_set();
recursive_insert = true;
new(regions_) RegionSet();
HandleSavedRegionsLocked(&DoInsertRegionLocked);
recursive_insert = false;
InitRegionSetLocked();
}
recursive_insert = true;
// Do the actual insertion work to put new regions into regions_:

View File

@ -362,6 +362,9 @@ class MemoryRegionMap {
// table where all buckets eventually should be.
static void RestoreSavedBucketsLocked();
// Initialize RegionSet regions_.
inline static void InitRegionSetLocked();
// Wrapper around DoInsertRegionLocked
// that handles the case of recursive allocator calls.
inline static void InsertRegionLocked(const Region& region);