Fix mmap leakage for ASAN build
When address_sanitizer is enable, mmap size will be added an extra
redzone_size. We need to add back to prevent a leakage.
Bug: 147272193
Test: boot
Test: adb shell pm compile -m speed-profile package_name
Test: art/test/testrunner/run_build_test_target.py -j32 art-asan
Change-Id: I5c0792ec779b2efa02e969889ebc54f0c2e7d6e3
diff --git a/libartbase/base/mem_map.cc b/libartbase/base/mem_map.cc
index 03e8218..bd880da 100644
--- a/libartbase/base/mem_map.cc
+++ b/libartbase/base/mem_map.cc
@@ -597,19 +597,21 @@
void MemMap::DoReset() {
DCHECK(IsValid());
-
+ size_t real_base_size = base_size_;
// Unlike Valgrind, AddressSanitizer requires that all manually poisoned memory is unpoisoned
// before it is returned to the system.
if (redzone_size_ != 0) {
+ // Add redzone_size_ back to base_size or it will cause a mmap leakage.
+ real_base_size += redzone_size_;
MEMORY_TOOL_MAKE_UNDEFINED(
- reinterpret_cast<char*>(base_begin_) + base_size_ - redzone_size_,
+ reinterpret_cast<char*>(base_begin_) + real_base_size - redzone_size_,
redzone_size_);
}
if (!reuse_) {
MEMORY_TOOL_MAKE_UNDEFINED(base_begin_, base_size_);
if (!already_unmapped_) {
- int result = TargetMUnmap(base_begin_, base_size_);
+ int result = TargetMUnmap(base_begin_, real_base_size);
if (result == -1) {
PLOG(FATAL) << "munmap failed";
}