Reviewers: Michael Starzinger,

Description:
Don't ignore return value of CommitCodePage in AllocateAlignedMemory.

Release the mapping as whole if commit failed to avoid leaking virtual address
space.

[email protected]
BUG=chromium:118625


Please review this at https://chromiumcodereview.appspot.com/10260012/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files:
  M src/spaces.h
  M src/spaces.cc


Index: src/spaces.cc
diff --git a/src/spaces.cc b/src/spaces.cc
index 6144464304898fdb3fe814cceeadc87f5e48881d..a5d61ebb59c6f09ae7f4f523c7d801224f7ed7fd 100644
--- a/src/spaces.cc
+++ b/src/spaces.cc
@@ -362,15 +362,22 @@ Address MemoryAllocator::AllocateAlignedMemory(size_t size,
   if (base == NULL) return NULL;

   if (executable == EXECUTABLE) {
-    CommitCodePage(&reservation, base, size);
+    if (!CommitCodePage(&reservation, base, size)) {
+      base = NULL;
+    }
   } else {
-    if (!reservation.Commit(base,
-                            size,
-                            executable == EXECUTABLE)) {
-      return NULL;
+    if (!reservation.Commit(base, size, false)) {
+      base = NULL;
     }
   }

+  if (base == NULL) {
+    // Failed to commit the body. Release the mapping and any partially
+    // commited regions inside it.
+    reservation.Release();
+    return NULL;
+  }
+
   controller->TakeControl(&reservation);
   return base;
 }
Index: src/spaces.h
diff --git a/src/spaces.h b/src/spaces.h
index de9f0b596668b6271ac982e1bb72c6e57f5a9f96..b0ecc5d0040278c19cf9778d6c9524506880e33c 100644
--- a/src/spaces.h
+++ b/src/spaces.h
@@ -1042,7 +1042,9 @@ class MemoryAllocator {
     return CodePageAreaEndOffset() - CodePageAreaStartOffset();
   }

- static bool CommitCodePage(VirtualMemory* vm, Address start, size_t size);
+  MUST_USE_RESULT static bool CommitCodePage(VirtualMemory* vm,
+                                             Address start,
+                                             size_t size);

  private:
   Isolate* isolate_;


--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to