Hi all, After some digging, it looks like the code in C_rereclaim2 which simply returns when the heap can't be resized is really really wrong.
I'm unsure what the "proper" fix is, but panicking seems like a good thing to do in the face of unreclaimable memory! See ticket #892 for details. Attached is a simple patch which inserts said panic(), and fixes a minor typo in another error (it also adds the word "new" to distinguish it from the other "out of memory" error on line 3328) Cheers, Peter -- http://www.more-magic.net
>From 274b81ee4b482ab702f80931c0ce63727c419381 Mon Sep 17 00:00:00 2001 From: Peter Bex <peter....@xs4all.nl> Date: Fri, 26 Jul 2013 21:48:08 +0200 Subject: [PATCH] Panic when maximum heap size exhausted, instead of crashing hard (fixes #892). It used to simply return from C_rereclaim2 and carry on as if the heap was resized(!) --- NEWS | 1 + runtime.c | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index 0f77a4c..2d9ab2b 100644 --- a/NEWS +++ b/NEWS @@ -48,6 +48,7 @@ - Special events in poll() are now handled, avoiding hangs in threaded apps. - When invoking procedures with many rest arguments directly (not via APPLY), raise an error when argument count limit was reached instead of crashing. + - When the maximum allowed heap size is reached, panic instead of crashing. - C API - Deprecated C_get_argument[_2] and C_get_environment_variable[_2] functions. diff --git a/runtime.c b/runtime.c index bbeb2f6..ef138e8 100644 --- a/runtime.c +++ b/runtime.c @@ -3305,7 +3305,8 @@ C_regparm void C_fcall C_rereclaim2(C_uword size, int double_plus) if(size > C_maximal_heap_size) size = C_maximal_heap_size; - if(size == heap_size) return; + if(size == heap_size) + panic(C_text("Maximum allowed heap size exceeded")); if(debug_mode) C_dbg(C_text("debug"), C_text("resizing heap dynamically from " UWORD_COUNT_FORMAT_STRING "k to " UWORD_COUNT_FORMAT_STRING "k ...\n"), @@ -3417,7 +3418,7 @@ C_regparm void C_fcall C_rereclaim2(C_uword size, int double_plus) heap_free (heapspace2, heapspace2_size); if ((heapspace2 = heap_alloc (size, &tospace_start)) == NULL) - panic(C_text("out ot memory - cannot allocate heap segment")); + panic(C_text("out of memory - cannot allocate next heap segment")); heapspace2_size = size; heapspace1 = new_heapspace; -- 1.8.2.3
_______________________________________________ Chicken-hackers mailing list Chicken-hackers@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-hackers