Hello hackers,
attached is a simple patch that fixes #1257 by making sure we don't
try to resize the heap whenever we hit the maximum size.

Cheers,
LemonBoy
From 1e9864ab4e32ddd36b305684324b14d9a550c64c Mon Sep 17 00:00:00 2001
From: LemonBoy <[email protected]>
Date: Fri, 3 Mar 2017 17:24:31 +0100
Subject: [PATCH] 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.
---
 runtime.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/runtime.c b/runtime.c
index a3298810..4c57b5c5 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) {
-- 
2.12.0

_______________________________________________
Chicken-hackers mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/chicken-hackers

Reply via email to