diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2021-09-13 00:06:20 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2021-09-13 00:06:20 -0700 |
commit | a2fa1cd7306a9f924604c7175e48ac63e4bd0958 (patch) | |
tree | a63901ee7fcba491b80016e175ca188729ff2c09 | |
parent | bab1a070c5f5d99b7efa1bfb2eb7e82fa7595e11 (diff) | |
download | txr-a2fa1cd7306a9f924604c7175e48ac63e4bd0958.tar.gz txr-a2fa1cd7306a9f924604c7175e48ac63e4bd0958.tar.bz2 txr-a2fa1cd7306a9f924604c7175e48ac63e4bd0958.zip |
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.
-rw-r--r-- | hash.c | 2 |
1 files changed, 1 insertions, 1 deletions
@@ -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; |