From 72b5b984b34487d9d978901db6d441317a7487ce Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Wed, 27 Mar 2013 16:44:13 -0600 Subject: [PATCH] places: fix problem in clean-up The problem was created by recent changes to allow GC of threads that are blocked on certain place channels. --- src/racket/src/place.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/racket/src/place.c b/src/racket/src/place.c index 76bd845f90..27cdb555a7 100644 --- a/src/racket/src/place.c +++ b/src/racket/src/place.c @@ -2979,6 +2979,11 @@ static void bi_channel_refcount_down(void *_ch, void *data) { Scheme_Place_Bi_Channel *ch = (Scheme_Place_Bi_Channel *)_ch; + if (!ch->link->sendch) { + /* released by scheme_free_place_bi_channels() already */ + return; + } + if (ch->link->prev) ch->link->prev->next = ch->link->next; else @@ -2996,7 +3001,11 @@ void scheme_free_place_bi_channels() for (link = place_channel_links; link; link = link->next) { async_channel_refcount(link->sendch, 1, -1); async_channel_refcount(link->recvch, 0, -1); + /* It's possible that a GC will run after this: */ + link->sendch = NULL; + link->recvch = NULL; } + place_channel_links = NULL; } static void bi_channel_set_finalizer(Scheme_Place_Bi_Channel *ch)