summaryrefslogtreecommitdiff
path: root/rts
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2022-05-23 23:00:32 -0400
committerMarge Bot <ben+marge-bot@smart-cactus.org>2022-06-18 10:42:54 -0400
commitcadd775397a88889bb6be6aca34469eea8ba17ec (patch)
tree6dc512f753e2b800b960e7ca315c31b27c09ec2a /rts
parent229d741f9907f0a07c475291fe3b1dbfcfea7aab (diff)
downloadhaskell-cadd775397a88889bb6be6aca34469eea8ba17ec.tar.gz
ghc-heap: Don't Box NULL pointers
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",