summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2018-10-26 06:58:44 -0700
committerKaz Kylheku <kaz@kylheku.com>2018-10-26 06:58:44 -0700
commitf302454e5eeeba9e06ddba96c10b1c296e5f359a (patch)
tree20d4aa7a36935ecdbb1e226dad3f36f1188d8f54
parenta6a4580a246d46a4de20805781d0d908ed6bf4a2 (diff)
downloadtxr-f302454e5eeeba9e06ddba96c10b1c296e5f359a.tar.gz
txr-f302454e5eeeba9e06ddba96c10b1c296e5f359a.tar.bz2
txr-f302454e5eeeba9e06ddba96c10b1c296e5f359a.zip
vm: bugfix: corruption of global desc list.
* vm.c (vm_make_desc): We must register the newly malloced descriptor structure into the free list before calling cobj, because calling cobj may trigger gc, which can blow away the object pointed to by our vtail local variable. Alternatively, we calculate vtail after doign the cobj. Obtaining vtail and using it cannot be separated by gc.
-rw-r--r--vm.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/vm.c b/vm.c
index 4c66309d..c0beeb53 100644
--- a/vm.c
+++ b/vm.c
@@ -157,6 +157,11 @@ val vm_make_desc(val nlevels, val nregs, val bytecode,
vd->self = nil;
+ vd->lnk.prev = vtail;
+ vd->lnk.next = vnull;
+ vnull->lnk.prev = vd;
+ vtail->lnk.next = vd;
+
desc = cobj(coerce(mem_t *, vd), vm_desc_s, &vm_desc_ops);
vd->bytecode = bytecode;
@@ -164,11 +169,6 @@ val vm_make_desc(val nlevels, val nregs, val bytecode,
vd->symvec = symvec;
vd->self = desc;
- vd->lnk.prev = vtail;
- vd->lnk.next = vnull;
- vnull->lnk.prev = vd;
- vtail->lnk.next = vd;
-
return desc;
}
}