Fix: VirtualAlloc leaks when freeing the heap on win32
authorMax Mouratov <mmouratov@gmail.com>
Sun, 21 Oct 2012 14:39:17 +0000 (20:39 +0600)
committerMax Mouratov <mmouratov@gmail.com>
Sun, 21 Oct 2012 14:39:17 +0000 (20:39 +0600)
os_dep.c

index da0f24d737c4b883d2f14838edbcea6a57e9b628..7efa08710ccd9e6a1ff6b4352539f4a76c8eb56a 100644 (file)
--- a/os_dep.c
+++ b/os_dep.c
@@ -2259,7 +2259,14 @@ void * os2_alloc(size_t bytes)
 #       endif
         GC_heap_bases[GC_n_heap_bases] = 0;
       }
-    }
+
+    // Avoiding the VirtualAlloc leak
+    } else {
+        while (GC_n_heap_bases > 0) {
+          VirtualFree(GC_heap_bases[--GC_n_heap_bases], 0, MEM_RELEASE);
+          GC_heap_bases[GC_n_heap_bases] = 0;
+        }
+      }
   }
 #endif /* MSWIN32 || CYGWIN32 */