From 9ba7834442acbb5400743a71300970ee6f859ec3 Mon Sep 17 00:00:00 2001 From: Joran Siu Date: Tue, 2 Oct 2018 11:16:58 -0400 Subject: [PATCH] Ensure reservation_ is initialized correctly Fix an issue introduced in commit 12d693dee30874be1883f90bff8ba88bca03fc6f where reservation_ field may not be initalized with the result of a successful anon_mmap() call. In the deconstructor, the memory is released based on reservation_ value. Signed-off-by: Joran Siu --- src/base/platform/platform-zos.cc | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/base/platform/platform-zos.cc b/src/base/platform/platform-zos.cc index 30753f6f54..8405a4b1d9 100644 --- a/src/base/platform/platform-zos.cc +++ b/src/base/platform/platform-zos.cc @@ -328,7 +328,7 @@ VirtualMemory::VirtualMemory(size_t size, size_t alignment) : address_(NULL), size_(0), reservation_(NULL) { DCHECK((alignment % OS::AllocateAlignment()) == 0); //Memory pages with 1MB alignment will be allocated using __moservices - bool rmode64 = SysInfo::ExecutablePagesAbove2GB(); + bool rmode64 = SysInfo::ExecutablePagesAbove2GB(); if (rmode64 && size % kMegaByte == 0) { void * reservation = anon_mmap(OS::GetRandomMmapAddr(), size); @@ -348,19 +348,21 @@ VirtualMemory::VirtualMemory(size_t size, size_t alignment) //to allocate memory with requested size and alignment, since there will //be some fragmentation by going down this path if (reservation == MAP_FAILED) { - request_size = RoundUp(size + alignment, - static_cast(kMegaByte)); - reservation = anon_mmap(OS::GetRandomMmapAddr(), - request_size); - if (reservation == MAP_FAILED) return; - reservation_ = reservation; - - uint8_t * base = static_cast(reservation_); - uint8_t * aligned_base = RoundUp(base, alignment); - DCHECK_LE(base, aligned_base); - address_ = aligned_base; - size = request_size; - return; + request_size = RoundUp(size + alignment, + static_cast(kMegaByte)); + reservation = anon_mmap(OS::GetRandomMmapAddr(), + request_size); + + if (reservation == MAP_FAILED) + return; + + uint8_t * base = static_cast(reservation); + uint8_t * aligned_base = RoundUp(base, alignment); + DCHECK_LE(base, aligned_base); + address_ = aligned_base; + size = request_size; + reservation_ = reservation; + return; } uint8_t* base = static_cast(reservation); @@ -386,6 +388,7 @@ VirtualMemory::VirtualMemory(size_t size, size_t alignment) address_ = static_cast(aligned_base); size_ = aligned_size; + reservation_ = reservation; #if defined(LEAK_SANITIZER) __lsan_register_root_region(address_, size_); #endif