From: Ivan Maidanski Date: Tue, 11 Sep 2012 04:30:25 +0000 (+0400) Subject: Fix min_bytes_allocd preventing potential infinite loop in GC_allocobj X-Git-Tag: gc7_4_0~214 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8102d42dd2e5b398e1085d5e3a90fdbee5ed6ed1;p=gc 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. --- 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;