From b00e93abd1ea964d44f719037216e8b7530578d3 Mon Sep 17 00:00:00 2001 From: Aleksey Bragin Date: Sun, 10 Oct 2010 21:52:48 +0000 Subject: [PATCH] [HEAP] - Properly set HEAP_GROWABLE flag if dwMaximumSize is 0 in HeapCreate. Also check for dwMaximumSize validity. Fixes out-of-memory problems when running "heavy" applications like Office 2003 setup with a new heap manager (which actually respects HEAP_GROWABLE flag). svn path=/trunk/; revision=49102 --- reactos/dll/win32/kernel32/mem/heap.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/reactos/dll/win32/kernel32/mem/heap.c b/reactos/dll/win32/kernel32/mem/heap.c index 41228b737aa..80aefa15cbe 100644 --- a/reactos/dll/win32/kernel32/mem/heap.c +++ b/reactos/dll/win32/kernel32/mem/heap.c @@ -13,6 +13,10 @@ #define NDEBUG #include +/* TYPES *********************************************************************/ + +extern SYSTEM_BASIC_INFORMATION BaseCachedSysInfo; + /* FUNCTIONS ***************************************************************/ /* @@ -31,6 +35,17 @@ HeapCreate(DWORD flOptions, Flags = (flOptions & (HEAP_GENERATE_EXCEPTIONS | HEAP_NO_SERIALIZE)) | HEAP_CLASS_1; + /* Check if heap is growable and ensure max size is correct */ + if (dwMaximumSize == 0) + Flags |= HEAP_GROWABLE; + else if (dwMaximumSize < BaseCachedSysInfo.PageSize && + dwInitialSize > dwMaximumSize) + { + /* Max size is non-zero but less than page size which can't be correct. + Fix it up by bumping it to the initial size whatever it is. */ + dwMaximumSize = dwInitialSize; + } + /* Call RTL Heap */ hRet = RtlCreateHeap(Flags, NULL,