From 8a04df087c1e77cc080936ac6e023cbb67feefdd Mon Sep 17 00:00:00 2001 From: Zentrik Date: Mon, 18 Dec 2023 21:37:22 +0000 Subject: [PATCH] Fix GC rooting during rehashing of iddict (#52569) Should fix #52558. `a` should be rooted before the alloc call. I removed the comment as it seemed to refer to a write barrier that was removed long ago. (cherry picked from commit 5977cb0a0c1ef98fa0e4019bf1a41380a717be6f) --- src/iddict.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/iddict.c b/src/iddict.c index 1fa8a67d1ae96..3cd39e6aa9433 100644 --- a/src/iddict.c +++ b/src/iddict.c @@ -15,15 +15,14 @@ JL_DLLEXPORT jl_array_t *jl_idtable_rehash(jl_array_t *a, size_t newsz) size_t sz = jl_array_len(a); size_t i; jl_value_t **ol = (jl_value_t **)a->data; - jl_array_t *newa = jl_alloc_vec_any(newsz); + jl_array_t *newa = NULL; // keep the original array in the original slot since we need `ol` // to be valid in the loop below. JL_GC_PUSH2(&newa, &a); + newa = jl_alloc_vec_any(newsz); for (i = 0; i < sz; i += 2) { if (ol[i + 1] != NULL) { jl_table_assign_bp(&newa, ol[i], ol[i + 1]); - // it is however necessary here because allocation - // can (and will) occur in a recursive call inside table_lookup_bp } } JL_GC_POP();