Index: base/allocator/win_allocator.cc |
diff --git a/base/allocator/win_allocator.cc b/base/allocator/win_allocator.cc |
index ee451f546101c008c0b081f4c880790c20027bd6..279606c26e4a675f314fd3e3a8eab39a3bc74ed8 100644 |
--- a/base/allocator/win_allocator.cc |
+++ b/base/allocator/win_allocator.cc |
@@ -6,27 +6,33 @@ |
extern "C" { |
+const size_t kWindowsPageSize = 4096; |
+size_t kMaxWindowsAllocation = |
+ std::numeric_limits<int>::max() - kWindowsPageSize; |
HANDLE win_heap; |
-bool win_heap_init(bool use_lfh) { |
- win_heap = HeapCreate(0, 0, 0); |
+bool win_heap_init() { |
+ win_heap = static_cast<HANDLE>(GetProcessHeap()); |
if (win_heap == NULL) |
return false; |
- if (use_lfh) { |
- ULONG enable_lfh = 2; |
- HeapSetInformation(win_heap, HeapCompatibilityInformation, |
- &enable_lfh, sizeof(enable_lfh)); |
- // NOTE: Setting LFH may fail. Vista already has it enabled. |
- // And under the debugger, it won't use LFH. So we |
- // ignore any errors. |
- } |
+ ULONG enable_lfh = 2; |
+ // NOTE: Setting LFH may fail. Vista already has it enabled. |
+ // And under the debugger, it won't use LFH. So we |
+ // ignore any errors. |
+ HeapSetInformation(win_heap, HeapCompatibilityInformation, &enable_lfh, |
+ sizeof(enable_lfh)); |
+ // In Debug, _mt_init() performs an allocation before _cinit is called to |
+ // initalize C data, so manually initialize kMaxWindowsAllocation here. |
+ kMaxWindowsAllocation = std::numeric_limits<int>::max() - kWindowsPageSize; |
return true; |
} |
void* win_heap_malloc(size_t size) { |
- return HeapAlloc(win_heap, 0, size); |
+ if (size < kMaxWindowsAllocation) |
+ return HeapAlloc(win_heap, 0, size); |
+ return NULL; |
} |
void win_heap_free(void* size) { |
@@ -40,7 +46,9 @@ void* win_heap_realloc(void* ptr, size_t size) { |
win_heap_free(ptr); |
return NULL; |
} |
- return HeapReAlloc(win_heap, 0, ptr, size); |
+ if (size < kMaxWindowsAllocation) |
+ return HeapReAlloc(win_heap, 0, ptr, size); |
+ return NULL; |
} |
size_t win_heap_msize(void* ptr) { |