~ chicken-core (chicken-5) 31d154d1623df7f8cb33909205ad07cb3ec7e66a


commit 31d154d1623df7f8cb33909205ad07cb3ec7e66a
Author:     LemonBoy <thatlemon@gmail.com>
AuthorDate: Fri Mar 3 17:24:31 2017 +0100
Commit:     Evan Hanson <evhan@foldling.org>
CommitDate: Mon Mar 13 10:33:29 2017 +1300

    Prevent an infinite loop when the heap is resized.
    
    When the heap has already reached its maximum size and we try to expand
    it farther the resize operation becomes a no-op.
    
    Signed-off-by: Peter Bex <peter@more-magic.net>
    Signed-off-by: Evan Hanson <evhan@foldling.org>

diff --git a/runtime.c b/runtime.c
index 946a2f75..00b9a557 100644
--- a/runtime.c
+++ b/runtime.c
@@ -3447,7 +3447,14 @@ C_regparm void C_fcall C_rereclaim2(C_uword size, int relative_resize)
    */
   if(size > heap_size && size - heap_size < stack_size * 2)
     size = heap_size + stack_size * 2;
-	  
+
+  /*
+   * The heap has grown but we've already hit the maximal size with the current
+   * heap, we can't do anything else but panic.
+   */
+  if(size > heap_size && heap_size >= C_maximal_heap_size)
+    panic(C_text("out of memory - heap has reached its maximum size"));
+
   if(size > C_maximal_heap_size) size = C_maximal_heap_size;
 
   if(debug_mode) {
Trap