From 8102d42dd2e5b398e1085d5e3a90fdbee5ed6ed1 Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Tue, 11 Sep 2012 08:30:25 +0400 Subject: [PATCH] Fix min_bytes_allocd preventing potential infinite loop in GC_allocobj * alloc.c (min_bytes_allocd): Do not return zero in case of big GC_free_space_divisor value (return 1 instead to prevent infinite loop in GC_allocobj if GC_adj_bytes_allocd returns zero); update comment. --- alloc.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/alloc.c b/alloc.c index 28d78e44..aca7980d 100644 --- a/alloc.c +++ b/alloc.c @@ -197,9 +197,10 @@ GC_API GC_stop_func GC_CALL GC_get_stop_func(void) #endif /* Return the minimum number of words that must be allocated between */ -/* collections to amortize the collection cost. */ +/* collections to amortize the collection cost. Should be non-zero. */ static word min_bytes_allocd(void) { + word result; # ifdef STACK_GROWS_UP word stack_size = GC_approx_sp() - GC_stackbottom; /* GC_stackbottom is used only for a single-threaded case. */ @@ -228,11 +229,11 @@ static word min_bytes_allocd(void) total_root_size = 2 * stack_size + GC_root_size; scan_size = 2 * GC_composite_in_use + GC_atomic_in_use / 4 + total_root_size; + result = scan_size / GC_free_space_divisor; if (GC_incremental) { - return scan_size / (2 * GC_free_space_divisor); - } else { - return scan_size / GC_free_space_divisor; + result /= 2; } + return result > 0 ? result : 1; } STATIC word GC_non_gc_bytes_at_gc = 0; -- 2.40.0