From: Simon Marlow Date: Mon, 28 Jun 2010 09:05:36 +0000 (+0000) Subject: during shutdown, only free the heap if we waited for foreign calls to exit X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=ae03da75d16d5d6e00c6f12102846509060a1138;p=ghc-hetmet.git during shutdown, only free the heap if we waited for foreign calls to exit --- diff --git a/rts/RtsStartup.c b/rts/RtsStartup.c index b0cddbd..d7a8d95 100644 --- a/rts/RtsStartup.c +++ b/rts/RtsStartup.c @@ -450,8 +450,11 @@ hs_exit_(rtsBool wait_foreign) /* free hash table storage */ exitHashTable(); - // Finally, free all our storage - freeStorage(); + // Finally, free all our storage. However, we only free the heap + // memory if we have waited for foreign calls to complete; + // otherwise a foreign call in progress may still be referencing + // heap memory (e.g. by being passed a ByteArray#). + freeStorage(wait_foreign); #if defined(DEBUG) /* and shut down the allocator debugging */ diff --git a/rts/sm/Storage.c b/rts/sm/Storage.c index c9422e6..10a0a38 100644 --- a/rts/sm/Storage.c +++ b/rts/sm/Storage.c @@ -213,10 +213,10 @@ exitStorage (void) } void -freeStorage (void) +freeStorage (rtsBool free_heap) { stgFree(generations); - freeAllMBlocks(); + if (free_heap) freeAllMBlocks(); #if defined(THREADED_RTS) closeMutex(&sm_mutex); #endif diff --git a/rts/sm/Storage.h b/rts/sm/Storage.h index f6c50ad..e541193 100644 --- a/rts/sm/Storage.h +++ b/rts/sm/Storage.h @@ -19,7 +19,7 @@ void initStorage(void); void exitStorage(void); -void freeStorage(void); +void freeStorage(rtsBool free_heap); /* ----------------------------------------------------------------------------- Storage manager state