]> granicus.if.org Git - gc/commitdiff
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)
committerIvan Maidanski <ivmai@mail.ru>
Sun, 23 Dec 2012 16:13:12 +0000 (17:13 +0100)
os_dep.c

index df5ebdb042eda48af309987a8f30eabf61da1259..2074f4658b6c892514af0f0892739afa896b85fb 100644 (file)
--- a/os_dep.c
+++ b/os_dep.c
@@ -2308,7 +2308,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 /* USE_WINALLOC || CYGWIN32 */