From 9f2ceb4da7dfbc1cfd09ce54610ebe64288b9007 Mon Sep 17 00:00:00 2001 From: Simon Marlow Date: Tue, 8 Aug 2006 10:31:10 +0000 Subject: Remember to free() memory on exit Patch mostly from Lennart Augustsson in #803, with additions to Task.c by me. --- rts/Hash.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'rts/Hash.c') 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); + } +} -- cgit v1.2.1