From 487277ad029c9df35281bebbe40fbf83eb281ef9 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Wed, 23 Oct 2019 17:27:29 -0600 Subject: [PATCH] cs & thread: fix use of custodian weak reference Commit 77023aeaba made the reference from a custodian-managed value to the custodian weak, and that could cause a crash in certain shutdown cases. Relevant to #2867 --- racket/src/thread/custodian.rkt | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/racket/src/thread/custodian.rkt b/racket/src/thread/custodian.rkt index 2ffbad90d8..48a4950d0a 100644 --- a/racket/src/thread/custodian.rkt +++ b/racket/src/thread/custodian.rkt @@ -158,13 +158,14 @@ (when cref (atomically (define c (custodian-reference->custodian cref)) - (unless (custodian-shut-down? c) - (hash-remove! (custodian-children c) obj)) - (host:disable-interrupts) - (define gc-roots (custodian-gc-roots c)) - (when gc-roots - (hash-remove! gc-roots obj)) - (host:enable-interrupts)) + (when c + (unless (custodian-shut-down? c) + (hash-remove! (custodian-children c) obj)) + (host:disable-interrupts) + (define gc-roots (custodian-gc-roots c)) + (when gc-roots + (hash-remove! gc-roots obj)) + (host:enable-interrupts))) (void))) ;; Called by scheduler (so atomic) when `c` is unreachable