summaryrefslogtreecommitdiff
path: root/rts
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2022-05-23 23:00:32 -0400
committerDouglas Wilson <douglas.wilson@gmail.com>2022-06-16 17:02:48 +0100
commit4d2db4a5547e88fb42ee74fa9d19566887ef4ac7 (patch)
treeccd53c2a1a90f5e3554532f15c4cb0c484342e8a /rts
parent49837c7f0ccb2971823d297c0fa0aea0c47a0487 (diff)
downloadhaskell-wip/T21622.tar.gz
ghc-heap: Don't Box NULL pointerswip/T21622
Previously we could construct a `Box` of a NULL pointer from the `link` field of `StgWeak`. Now we take care to avoid ever introducing such pointers in `collect_pointers` and ensure that the `link` field is represented as a `Maybe` in the `Closure` type. Fixes #21622
Diffstat (limited to 'rts')
-rw-r--r--rts/Heap.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/rts/Heap.c b/rts/Heap.c
index 09beb9a8d2..0594a46b0b 100644
--- a/rts/Heap.c
+++ b/rts/Heap.c
@@ -224,13 +224,18 @@ StgWord collect_pointers(StgClosure *closure, StgClosure *ptrs[]) {
ptrs[nptrs++] = (StgClosure *)((StgTSO *)closure)->bq;
break;
- case WEAK:
- ptrs[nptrs++] = (StgClosure *)((StgWeak *)closure)->cfinalizers;
- ptrs[nptrs++] = (StgClosure *)((StgWeak *)closure)->key;
- ptrs[nptrs++] = (StgClosure *)((StgWeak *)closure)->value;
- ptrs[nptrs++] = (StgClosure *)((StgWeak *)closure)->finalizer;
- ptrs[nptrs++] = (StgClosure *)((StgWeak *)closure)->link;
+ case WEAK: {
+ StgWeak *w = (StgWeak *)closure;
+ ptrs[nptrs++] = (StgClosure *) w->cfinalizers;
+ ptrs[nptrs++] = (StgClosure *) w->key;
+ ptrs[nptrs++] = (StgClosure *) w->value;
+ ptrs[nptrs++] = (StgClosure *) w->finalizer;
+ // link may be NULL which is not a valid GC pointer
+ if (w->link) {
+ ptrs[nptrs++] = (StgClosure *) w->link;
+ }
break;
+ }
default:
fprintf(stderr,"closurePtrs: Cannot handle type %s yet\n",