Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(379)

Unified Diff: src/platform-macos.cc

Issue 8060052: Fix leakage of virtual address space on Linux platform. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/platform-linux.cc ('k') | src/platform-openbsd.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/platform-macos.cc
diff --git a/src/platform-macos.cc b/src/platform-macos.cc
index 0ac8fbe2d74771226ed470974fe70d166f3d35e8..a70b43c0276b2bc3425f3782789d83e814828860 100644
--- a/src/platform-macos.cc
+++ b/src/platform-macos.cc
@@ -228,7 +228,7 @@ OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name, int size,
PosixMemoryMappedFile::~PosixMemoryMappedFile() {
- if (memory_) munmap(memory_, size_);
+ if (memory_) OS::Free(memory_, size_);
fclose(file_);
}
@@ -353,21 +353,31 @@ VirtualMemory::VirtualMemory(size_t size, size_t alignment)
kMmapFd,
kMmapFdOffset);
if (reservation == MAP_FAILED) return;
+
Address base = static_cast<Address>(reservation);
Address aligned_base = RoundUp(base, alignment);
- ASSERT(base <= aligned_base);
+ ASSERT_LE(base, aligned_base);
// Unmap extra memory reserved before and after the desired block.
- size_t bytes_prior = static_cast<size_t>(aligned_base - base);
- if (bytes_prior > 0) {
- munmap(base, bytes_prior);
+ if (aligned_base != base) {
+ size_t prefix_size = static_cast<size_t>(aligned_base - base);
+ OS::Free(base, prefix_size);
+ request_size -= prefix_size;
}
- if (static_cast<size_t>(aligned_base - base) < request_size - size) {
- munmap(aligned_base + size, request_size - size - bytes_prior);
+
+ size_t aligned_size = RoundUp(size, OS::AllocateAlignment());
+ ASSERT_LE(aligned_size, request_size);
+
+ if (aligned_size != request_size) {
+ size_t suffix_size = request_size - aligned_size;
+ OS::Free(aligned_base + aligned_size, suffix_size);
+ request_size -= suffix_size;
}
+ ASSERT(aligned_size == request_size);
+
address_ = static_cast<void*>(aligned_base);
- size_ = size;
+ size_ = aligned_size;
}
« no previous file with comments | « src/platform-linux.cc ('k') | src/platform-openbsd.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698