diff --git a/src/compat/alloc.c b/src/compat/alloc.c index 2480ef2..aa7f1fc 100644 --- a/src/compat/alloc.c +++ b/src/compat/alloc.c @@ -28,8 +28,28 @@ #ifdef VANILLA_WIN32 HANDLE g_heap; +struct garbage_heap { + HANDLE handle; + struct garbage_heap *next; +}; + +# define HEAP_MIN_BASE 0x08000000 + void init_inheritable_heap(void) { - g_heap = HeapCreate(0, 0, 0); + struct garbage_heap *heaps = NULL; + + while ((void*)(g_heap = HeapCreate(0, 0, 0)) < (void*)HEAP_MIN_BASE) { + if (g_heap == NULL) + break; + + struct garbage_heap *heap = malloc(sizeof(struct garbage_heap)); + heap->handle = g_heap; + heap->next = heaps; + heaps = heap; + } + for (struct garbage_heap *h = heaps; h != NULL; h = h->next) + HeapDestroy(h->handle); + if (g_heap == (HANDLE) NULL) { fputs("Could not create the private inheritable heap.", stderr); abort(); diff --git a/src/compat/process.c b/src/compat/process.c index cf2281d..a553a05 100644 --- a/src/compat/process.c +++ b/src/compat/process.c @@ -169,8 +169,6 @@ static void CALLBACK handle_child_terminated(PVOID lpParameter, int resume_child(void) { #ifdef VANILLA_WIN32 - init_inheritable_heap(); - TCHAR mapping_name[128]; _sntprintf(mapping_name, 128, g_mapping_name, GetCurrentProcessId()); @@ -179,8 +177,10 @@ int resume_child(void) { FALSE, mapping_name); - if (sharedMem == NULL) + if (sharedMem == NULL) { + init_inheritable_heap(); return 0; + } struct full_context *ctx = (struct full_context *) MapViewOfFile(sharedMem, FILE_MAP_ALL_ACCESS,