[Git][ghc/ghc][wip/free-censuses] rts/ProfHeap: Free old allocations when reinitialising Censuses

Ben Gamari gitlab at gitlab.haskell.org
Wed Jun 24 20:09:03 UTC 2020



Ben Gamari pushed to branch wip/free-censuses at Glasgow Haskell Compiler / GHC


Commits:
e90af2f4 by Ben Gamari at 2020-06-24T16:08:56-04:00
rts/ProfHeap: Free old allocations when reinitialising Censuses

Previously when not LDV profiling we would repeatedly reinitialise
`censuses[0]` with `initEra`. This failed to free the `Arena` and
`HashTable` from the old census, resulting in a memory leak.

Fixes #18348.

- - - - -


1 changed file:

- rts/ProfHeap.c


Changes:

=====================================
rts/ProfHeap.c
=====================================
@@ -347,6 +347,16 @@ LDV_recordDead( const StgClosure *c, uint32_t size )
 STATIC_INLINE void
 initEra(Census *census)
 {
+    // N.B. When not LDV profiling we reinitialise the same Census over
+    // and over again. Consequently, we need to ensure that we free the
+    // resources from the previous census.
+    if (census->hash) {
+        freeHashTable(census->hash, NULL);
+    }
+    if (census->arena) {
+        arenaFree(census->arena);
+    }
+
     census->hash  = allocHashTable();
     census->ctrs  = NULL;
     census->arena = newArena();
@@ -511,6 +521,11 @@ initHeapProfiling(void)
 
     censuses = stgMallocBytes(sizeof(Census) * n_censuses, "initHeapProfiling");
 
+    // Ensure that arena and hash are NULL since otherwise initEra will attempt to free them.
+    for (unsigned int i=0; i < n_censuses; i++) {
+        censuses[i].arena = NULL;
+        censuses[i].hash = NULL;
+    }
     initEra( &censuses[era] );
 
     /* initProfilingLogFile(); */



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/e90af2f456f0430d11eea19b285986e732034798

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/e90af2f456f0430d11eea19b285986e732034798
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20200624/dfeace45/attachment-0001.html>


More information about the ghc-commits mailing list