during shutdown, only free the heap if we waited for foreign calls to exit
authorSimon Marlow <marlowsd@gmail.com>
Mon, 28 Jun 2010 09:05:36 +0000 (09:05 +0000)
committerSimon Marlow <marlowsd@gmail.com>
Mon, 28 Jun 2010 09:05:36 +0000 (09:05 +0000)
rts/RtsStartup.c
rts/sm/Storage.c
rts/sm/Storage.h

index b0cddbd..d7a8d95 100644 (file)
@@ -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 */
index c9422e6..10a0a38 100644 (file)
@@ -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
index f6c50ad..e541193 100644 (file)
@@ -19,7 +19,7 @@
 
 void initStorage(void);
 void exitStorage(void);
-void freeStorage(void);
+void freeStorage(rtsBool free_heap);
 
 /* -----------------------------------------------------------------------------
    Storage manager state