summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-09-13 00:06:20 -0700
committerKaz Kylheku <kaz@kylheku.com>2021-09-13 00:06:20 -0700
commita2fa1cd7306a9f924604c7175e48ac63e4bd0958 (patch)
treea63901ee7fcba491b80016e175ca188729ff2c09
parentbab1a070c5f5d99b7efa1bfb2eb7e82fa7595e11 (diff)
downloadtxr-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.c2
1 files changed, 1 insertions, 1 deletions
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;