~ chicken-core (chicken-5) a75a11e5161e4df3030b9e5bc1d72a389a603cd0


commit a75a11e5161e4df3030b9e5bc1d72a389a603cd0
Author:     LemonBoy <thatlemon@gmail.com>
AuthorDate: Fri Mar 3 17:24:31 2017 +0100
Commit:     Evan Hanson <evhan@foldling.org>
CommitDate: Mon Mar 13 11:47:34 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 af844df4..dd4b6682 100644
--- a/runtime.c
+++ b/runtime.c
@@ -3798,7 +3798,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