summaryrefslogtreecommitdiff
path: root/rts/Hash.c
diff options
context:
space:
mode:
authorSimon Marlow <simonmar@microsoft.com>2006-08-08 10:31:10 +0000
committerSimon Marlow <simonmar@microsoft.com>2006-08-08 10:31:10 +0000
commit9f2ceb4da7dfbc1cfd09ce54610ebe64288b9007 (patch)
treec8a72bc8d7e4663c9b5f789d54a6a69bfbba4340 /rts/Hash.c
parent3098d2143a5865f8f1fba1d7d72132b140f2de94 (diff)
downloadhaskell-9f2ceb4da7dfbc1cfd09ce54610ebe64288b9007.tar.gz
Remember to free() memory on exit
Patch mostly from Lennart Augustsson in #803, with additions to Task.c by me.
Diffstat (limited to 'rts/Hash.c')
-rw-r--r--rts/Hash.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/rts/Hash.c b/rts/Hash.c
index ada11a6a85..1d80640c4a 100644
--- a/rts/Hash.c
+++ b/rts/Hash.c
@@ -212,15 +212,25 @@ lookupHashTable(HashTable *table, StgWord key)
static HashList *freeList = NULL;
+static struct chunkList {
+ void *chunk;
+ struct chunkList *next;
+} *chunks;
+
static HashList *
allocHashList(void)
{
HashList *hl, *p;
+ struct chunkList *cl;
if ((hl = freeList) != NULL) {
freeList = hl->next;
} else {
hl = stgMallocBytes(HCHUNK * sizeof(HashList), "allocHashList");
+ cl = stgMallocBytes(sizeof (*cl), "allocHashList: chunkList");
+ cl->chunk = hl;
+ cl->next = chunks;
+ chunks = cl;
freeList = hl + 1;
for (p = freeList; p < hl + HCHUNK - 1; p++)
@@ -374,3 +384,15 @@ allocStrHashTable(void)
return allocHashTable_((HashFunction *)hashStr,
(CompareFunction *)compareStr);
}
+
+void
+exitHashTable(void)
+{
+ struct chunkList *cl;
+
+ while ((cl = chunks) != NULL) {
+ chunks = cl->next;
+ stgFree(cl->chunk);
+ stgFree(cl);
+ }
+}