From 093db6af247c603460b670faade912993b28eea3 Mon Sep 17 00:00:00 2001 From: daan Date: Mon, 20 Apr 2020 09:33:19 -0700 Subject: [PATCH] possible fix for memory instability on Win7 (#230) --- src/os.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/os.c b/src/os.c index 12ba9442..1c7e03c8 100644 --- a/src/os.c +++ b/src/os.c @@ -212,10 +212,12 @@ static void* mi_win_virtual_allocx(void* addr, size_t size, size_t try_alignment void* p = VirtualAlloc(hint, size, flags, PAGE_READWRITE); if (p != NULL) return p; DWORD err = GetLastError(); - if (err != ERROR_INVALID_ADDRESS) { // if linked with multiple instances, we may have tried to allocate at an already allocated area + if (err != ERROR_INVALID_ADDRESS && // If linked with multiple instances, we may have tried to allocate at an already allocated area (#210) + err != ERROR_INVALID_PARAMETER) { // Windows7 instability (#230) return NULL; } - } + // fall through + } #endif #if defined(MEM_EXTENDED_PARAMETER_TYPE_BITS) // on modern Windows try use VirtualAlloc2 for aligned allocation @@ -228,6 +230,7 @@ static void* mi_win_virtual_allocx(void* addr, size_t size, size_t try_alignment return (*pVirtualAlloc2)(GetCurrentProcess(), addr, size, flags, PAGE_READWRITE, ¶m, 1); } #endif + // last resort return VirtualAlloc(addr, size, flags, PAGE_READWRITE); }