From 06b53470f4c40f72d3df3501eeffa921d7922f35 Mon Sep 17 00:00:00 2001 From: Andy Wingo Date: Wed, 23 Apr 2025 16:44:59 +0200 Subject: [PATCH] For freelist allocators, clear the freelist link on the returned obj * api/gc-api.h (gc_allocate_small_fast_freelist): * src/bdw.c (allocate_small): Clear freelist link, so the object is completely zeroed. In some cases the embedder / compiler / JIT will be able to elide this write. --- api/gc-api.h | 1 + src/bdw.c | 1 + 2 files changed, 2 insertions(+) diff --git a/api/gc-api.h b/api/gc-api.h index c95c33a65..58f40b779 100644 --- a/api/gc-api.h +++ b/api/gc-api.h @@ -140,6 +140,7 @@ static inline void* gc_allocate_small_fast_freelist(struct gc_mutator *mut, return NULL; *freelist_loc = *(void**)head; + *(void**)head = NULL; gc_update_alloc_table(gc_ref_from_heap_object(head), size, kind); diff --git a/src/bdw.c b/src/bdw.c index 3e7bcf17c..886e70718 100644 --- a/src/bdw.c +++ b/src/bdw.c @@ -122,6 +122,7 @@ allocate_small(void **freelist, size_t idx, enum gc_inline_kind kind) { } *freelist = *(void **)(head); + *(void**)head = NULL; if (kind == GC_INLINE_KIND_POINTERLESS) memset(head, 0, gc_inline_freelist_object_size(idx));