From 132eb0bc220b7c2e32d43e9e5c290b17a7e6f37a Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Sat, 25 Mar 2023 00:04:55 +0300 Subject: Do not add extra byte to non-small uncollectible objects Previously EXTRA_BYTES value was not added to the allocation size only for small uncollectible objects. * include/gc/gc.h (GC_all_interior_pointers): Refine comment (regarding uncollectible objects). * malloc.c (GC_generic_malloc_uncollectable): Define lb_orig local variable; decrement lb before if(SMALL_OBJ(lb)); do not expect original lb is zero; pass lb_orig (instead of lb) to GC_DBG_COLLECT_AT_MALLOC() and to oom_fn(). --- malloc.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'malloc.c') diff --git a/malloc.c b/malloc.c index b104b11e..6a24da89 100644 --- a/malloc.c +++ b/malloc.c @@ -338,8 +338,13 @@ GC_API GC_ATTR_MALLOC void * GC_CALL GC_generic_malloc_uncollectable( size_t lb, int k) { void *op; + size_t lb_orig = lb; GC_ASSERT(k < MAXOBJKINDS); + if (EXTRA_BYTES != 0 && EXPECT(lb != 0, TRUE)) lb--; + /* We do not need the extra byte, since this will */ + /* not be collected anyway. */ + if (SMALL_OBJ(lb)) { void **opp; size_t lg; @@ -347,10 +352,7 @@ GC_API GC_ATTR_MALLOC void * GC_CALL GC_generic_malloc_uncollectable( if (EXPECT(get_have_errors(), FALSE)) GC_print_all_errors(); GC_INVOKE_FINALIZERS(); - GC_DBG_COLLECT_AT_MALLOC(lb); - if (EXTRA_BYTES != 0 && lb != 0) lb--; - /* We don't need the extra byte, since this won't be */ - /* collected anyway. */ + GC_DBG_COLLECT_AT_MALLOC(lb_orig); LOCK(); lg = GC_size_map[lb]; opp = &GC_obj_kinds[k].ok_freelist[lg]; @@ -368,7 +370,7 @@ GC_API GC_ATTR_MALLOC void * GC_CALL GC_generic_malloc_uncollectable( if (NULL == op) { GC_oom_func oom_fn = GC_oom_fn; UNLOCK(); - return (*oom_fn)(lb); + return (*oom_fn)(lb_orig); } /* For small objects, the free lists are completely marked. */ } -- cgit v1.2.1