fix potential GC problem while setting up a place channel

This commit is contained in:
Matthew Flatt 2015-09-22 16:36:55 -06:00
parent 5a33856802
commit aaf098f203

View File

@ -438,13 +438,17 @@ int BTC_bi_chan_mark(void *p, struct NewGC *gc)
{ {
if (gc->doing_memory_accounting) { if (gc->doing_memory_accounting) {
Scheme_Place_Bi_Channel *bc = (Scheme_Place_Bi_Channel *)p; Scheme_Place_Bi_Channel *bc = (Scheme_Place_Bi_Channel *)p;
/* Race conditions here on `mem_size', and likely double counting /* The `link` field can be NULL if the channel is still being
when the same async channels are accessible from paired bi set up: */
channels --- but those approximations are ok for accounting. */ if (bc->link) {
if (bc->link->sendch) /* Race conditions here on `mem_size', and likely double counting
account_memory(gc, gc->current_mark_owner, gcBYTES_TO_WORDS(bc->link->sendch->mem_size), 0); when the same async channels are accessible from paired bi
if (bc->link->recvch) channels --- but those approximations are ok for accounting. */
account_memory(gc, gc->current_mark_owner, gcBYTES_TO_WORDS(bc->link->recvch->mem_size), 0); if (bc->link->sendch)
account_memory(gc, gc->current_mark_owner, gcBYTES_TO_WORDS(bc->link->sendch->mem_size), 0);
if (bc->link->recvch)
account_memory(gc, gc->current_mark_owner, gcBYTES_TO_WORDS(bc->link->recvch->mem_size), 0);
}
} }
return gc->mark_table[btc_redirect_bi_chan](p, gc); return gc->mark_table[btc_redirect_bi_chan](p, gc);
} }