summaryrefslogtreecommitdiff
path: root/alloc.c
diff options
context:
space:
mode:
authorIvan Maidanski <ivmai@mail.ru>2012-09-11 08:30:25 +0400
committerIvan Maidanski <ivmai@mail.ru>2012-09-11 21:54:04 +0400
commit8102d42dd2e5b398e1085d5e3a90fdbee5ed6ed1 (patch)
tree0fb9b099d5f4e618540db8e1eae6a0ce79809a2d /alloc.c
parent382e5b032f20c58e14ca2c719c70e56382967174 (diff)
downloadbdwgc-8102d42dd2e5b398e1085d5e3a90fdbee5ed6ed1.tar.gz
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.
Diffstat (limited to 'alloc.c')
-rw-r--r--alloc.c9
1 files 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;