From a2fa1cd7306a9f924604c7175e48ac63e4bd0958 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Mon, 13 Sep 2021 00:06:20 -0700 Subject: hash: gc problem in copy-hash. * hash.c (copy_hash): The order of allocating the hash object and vector is incorrect. The hash must be allocated last, like it is in do_make_hash and make_similar_hash. If the vector is allocated after the hash, it can trigger gc, and then the garbage collector will traverse the uninitialized parts of the hash object. --- hash.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hash.c b/hash.c index 9c8bff2d..54ebc9dc 100644 --- a/hash.c +++ b/hash.c @@ -916,8 +916,8 @@ val copy_hash(val existing) struct hash *ex = coerce(struct hash *, cobj_handle(self, existing, hash_cls)); struct hash *h = coerce(struct hash *, chk_malloc(sizeof *h)); val mod = num_fast(ex->modulus); - val hash = cobj(coerce(mem_t *, h), hash_cls, &hash_ops); val table = vector(mod, nil); + val hash = cobj(coerce(mem_t *, h), hash_cls, &hash_ops); ucnum i; h->modulus = ex->modulus; -- cgit v1.2.3