Fix #2592: do an orderly shutdown when the heap is exhausted
[ghc-hetmet.git] / rts / sm / Storage.c
index bf7c452..6fa90cf 100644 (file)
@@ -617,6 +617,13 @@ allocateInGen (generation *g, lnat n)
         if (RtsFlags.GcFlags.maxHeapSize > 0 && 
             req_blocks >= RtsFlags.GcFlags.maxHeapSize) {
             heapOverflow();
+            // heapOverflow() doesn't exit (see #2592), but we aren't
+            // in a position to do a clean shutdown here: we
+            // either have to allocate the memory or exit now.
+            // Allocating the memory would be bad, because the user
+            // has requested that we not exceed maxHeapSize, so we
+            // just exit.
+           stg_exit(EXIT_HEAPOVERFLOW);
         }
 
        bd = allocGroup(req_blocks);