Free more things that we allocate 2006-12-16
authorIan Lynagh <igloo@earth.li>
Fri, 15 Dec 2006 21:44:30 +0000 (21:44 +0000)
committerIan Lynagh <igloo@earth.li>
Fri, 15 Dec 2006 21:44:30 +0000 (21:44 +0000)
rts/Capability.c
rts/Capability.h
rts/ProfHeap.c
rts/Profiling.c
rts/Profiling.h
rts/RtsSignals.h
rts/RtsStartup.c
rts/Schedule.c
rts/posix/Signals.c
rts/win32/ConsoleHandler.c

index 3d55b42..510656f 100644 (file)
@@ -673,8 +673,7 @@ shutdownCapability (Capability *cap, Task *task)
            continue;
        }
        debugTrace(DEBUG_sched, "capability %d is stopped.", cap->no);
-        stgFree(cap->mut_lists);
-        freeSparkPool(&cap->r.rSparks);
+    freeCapability(cap);
        RELEASE_LOCK(&cap->lock);
        break;
     }
@@ -712,4 +711,11 @@ tryGrabCapability (Capability *cap, Task *task)
 
 #endif /* THREADED_RTS */
 
+void
+freeCapability (Capability *cap) {
+    stgFree(cap->mut_lists);
+#if defined(THREADED_RTS) || defined(PARALLEL_HASKELL)
+    freeSparkPool(&cap->r.rSparks);
+#endif
+}
 
index dd17863..dedd635 100644 (file)
@@ -232,6 +232,9 @@ extern void grabCapability (Capability **pCap);
 
 #endif /* !THREADED_RTS */
 
+// Free a capability on exit
+void freeCapability (Capability *cap);
+
 /* -----------------------------------------------------------------------------
  * INLINE functions... private below here
  * -------------------------------------------------------------------------- */
index 4aecd0b..e93151d 100644 (file)
@@ -316,6 +316,13 @@ initEra(Census *census)
     census->drag_total = 0;
 }
 
+STATIC_INLINE void
+freeEra(Census *census)
+{
+    arenaFree(census->arena);
+    freeHashTable(census->hash, NULL);
+}
+
 /* --------------------------------------------------------------------------
  * Increases era by 1 and initialize census[era].
  * Reallocates gi[] and increases its size if needed.
@@ -355,6 +362,10 @@ void initProfiling1( void )
 {
 }
 
+void freeProfiling1( void )
+{
+}
+
 void initProfiling2( void )
 {
   if (RtsFlags.ProfFlags.doHeapProfile) {
@@ -493,6 +504,14 @@ endHeapProfiling(void)
     }
 #endif
 
+    {
+        nat t;
+        for (t = 0; t <= era; t++) {
+            freeEra( &censuses[t] );
+        }
+    }
+    stgFree(censuses);
+
     seconds = mut_user_time();
     printSample(rtsTrue, seconds);
     printSample(rtsFalse, seconds);
index a865078..4e759b6 100644 (file)
@@ -186,6 +186,12 @@ initProfiling1 (void)
 }
 
 void
+freeProfiling1 (void)
+{
+    arenaFree(prof_arena);
+}
+
+void
 initProfiling2 (void)
 {
   CostCentreStack *ccs, *next;
index d968349..edfc1b2 100644 (file)
@@ -13,6 +13,7 @@
 
 #if defined(PROFILING) || defined(DEBUG)
 void initProfiling1 ( void );
+void freeProfiling1 ( void );
 void initProfiling2 ( void );
 void endProfiling   ( void );
 
index eafeeaa..6d9374a 100644 (file)
@@ -41,6 +41,8 @@ extern void initUserSignals(void);
  */
 extern void initDefaultHandlers(void);
 
+extern void freeSignalHandlers(void);
+
 /*
  * Function: blockUserSignals()
  *
index 87df96a..7193876 100644 (file)
@@ -378,6 +378,10 @@ hs_exit(void)
     /* start timing the shutdown */
     stat_startExit();
     
+#if defined(RTS_USER_SIGNALS)
+    freeSignalHandlers();
+#endif
+
 #if defined(THREADED_RTS)
     ioManagerDie();
 #endif
@@ -447,6 +451,10 @@ hs_exit(void)
     /* free the stable pointer table */
     exitStablePtrTable();
 
+#if defined(PROFILING) || defined(DEBUG)
+    freeProfiling1();
+#endif
+
 #if defined(DEBUG)
     /* free the thread label table */
     freeThreadLabelTable();
index 8ebedd4..a11a15e 100644 (file)
@@ -2581,6 +2581,8 @@ exitScheduler( void )
        boundTaskExiting(task);
        stopTaskManager();
     }
+#else
+    freeCapability(&MainCapability);
 #endif
 }
 
@@ -2588,6 +2590,9 @@ void
 freeScheduler( void )
 {
     freeTaskManager();
+    if (n_capabilities != 1) {
+        stgFree(capabilities);
+    }
 #if defined(THREADED_RTS)
     closeMutex(&sched_mutex);
 #endif
index a5044cd..2380eac 100644 (file)
@@ -545,4 +545,11 @@ initDefaultHandlers()
 #endif
 }
 
+void
+freeSignalHandlers(void) {
+    if (signal_handlers != NULL) {
+        stgFree(signal_handlers);
+    }
+}
+
 #endif /* RTS_USER_SIGNALS */
index 5b5cfc3..a2de74b 100644 (file)
@@ -52,6 +52,11 @@ initUserSignals(void)
     return;
 }
 
+void
+freeSignalHandlers(void) {
+    /* Do nothing */
+}
+
 /* Seems to be a bit of an orphan...where used? */
 void
 finiUserSignals(void)