Skip to content

Commit

Permalink
Remember to free() memory on exit
Browse files Browse the repository at this point in the history
Patch mostly from Lennart Augustsson in #803, with additions to
Task.c by me.
  • Loading branch information
Simon Marlow committed Aug 8, 2006
1 parent 3098d21 commit 9f2ceb4
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 0 deletions.
3 changes: 3 additions & 0 deletions includes/Stable.h
Expand Up @@ -55,6 +55,7 @@ extern StgPtr deRefStablePtr(StgStablePtr sp);
#endif

extern void initStablePtrTable ( void );
extern void exitStablePtrTable ( void );
extern void enlargeStablePtrTable ( void );
extern StgWord lookupStableName ( StgPtr p );

Expand All @@ -63,4 +64,6 @@ extern void threadStablePtrTable ( evac_fn evac );
extern void gcStablePtrTable ( void );
extern void updateStablePtrTable ( rtsBool full );

extern void exitHashTable ( void );

#endif
22 changes: 22 additions & 0 deletions rts/Hash.c
Expand Up @@ -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++)
Expand Down Expand Up @@ -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);
}
}
6 changes: 6 additions & 0 deletions rts/RtsStartup.c
Expand Up @@ -390,6 +390,12 @@ hs_exit(void)
// also outputs the stats (+RTS -s) info.
exitStorage();

/* initialise the stable pointer table */
exitStablePtrTable();

/* free hash table storage */
exitHashTable();

#ifdef RTS_GTK_FRONTPANEL
if (RtsFlags.GcFlags.frontpanel) {
stopFrontPanel();
Expand Down
12 changes: 12 additions & 0 deletions rts/Stable.c
Expand Up @@ -159,6 +159,18 @@ initStablePtrTable(void)
#endif
}

void
exitStablePtrTable(void)
{
if (addrToStableHash)
freeHashTable(addrToStableHash, NULL);
addrToStableHash = NULL;
if (stable_ptr_table)
stgFree(stable_ptr_table);
stable_ptr_table = NULL;
SPT_size = 0;
}

/*
* get at the real stuff...remove indirections.
*
Expand Down
3 changes: 3 additions & 0 deletions rts/Stats.c
Expand Up @@ -537,6 +537,9 @@ stat_exit(int alloc)
statsFlush();
statsClose();
}
if (GC_coll_times)
stgFree(GC_coll_times);
GC_coll_times = NULL;
}

/* -----------------------------------------------------------------------------
Expand Down
5 changes: 5 additions & 0 deletions rts/Storage.c
Expand Up @@ -273,6 +273,11 @@ exitStorage (void)
void
freeStorage (void)
{
nat g;

for(g = 0; g < RtsFlags.GcFlags.generations; g++)
stgFree(generations[g].steps);
stgFree(generations);
freeAllMBlocks();
}

Expand Down
10 changes: 10 additions & 0 deletions rts/Task.c
Expand Up @@ -74,9 +74,19 @@ initTaskManager (void)
void
stopTaskManager (void)
{
Task *task, *next;

debugTrace(DEBUG_sched,
"stopping task manager, %d tasks still running",
tasksRunning);

ACQUIRE_LOCK(&sched_mutex);
for (task = task_free_list; task != NULL; next) {
next = task->next;
stgFree(task);
}
task_free_list = NULL;
RELEASE_LOCK(&sched_mutex);
}


Expand Down

0 comments on commit 9f2ceb4

Please sign in to comment.