From ae03da75d16d5d6e00c6f12102846509060a1138 Mon Sep 17 00:00:00 2001 From: Simon Marlow Date: Mon, 28 Jun 2010 09:05:36 +0000 Subject: [PATCH] during shutdown, only free the heap if we waited for foreign calls to exit --- rts/RtsStartup.c | 7 +++++-- rts/sm/Storage.c | 4 ++-- rts/sm/Storage.h | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) 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 -- 1.7.10.4