From 7388adcea7ebace8d8c299da0e7c2e7e93da9c83 Mon Sep 17 00:00:00 2001 From: Jonathan McDowell Date: Mon, 31 May 2004 23:46:58 +0000 Subject: [PATCH] cscvs to tla changeset 10 Author: noodles Date: 2002/09/08 10:35:44 Added destroyhash for cleanup when we're done using the hash. --- hash.c | 35 +++++++++++++++++++++++++++++++++++ hash.h | 8 ++++++++ 2 files changed, 43 insertions(+) diff --git a/hash.c b/hash.c index 47ec2d8..e29017c 100644 --- a/hash.c +++ b/hash.c @@ -38,6 +38,41 @@ void inithash(void) elements = 0; } +/** + * destroyhash - Clean up the hash after use. + * + * This function destroys the hash after use, freeing any memory that was + * used during its lifetime. + */ +void destroyhash(void) +{ + int i; + struct ll *curll = NULL; + struct ll *nextll = NULL; + + for (i = 0; i < HASHSIZE; i++) { + curll = hashtable[i]; + while (curll != NULL) { + nextll = curll->next; + /* + * TODO: The problem is the object has pointers that + * need freed too. + */ + free(curll->object); + free(curll); + curll = nextll; + } + hashtable[i] = NULL; + } + elements = 0; +} + +/** + * addtohash - Adds a key to the hash. + * @key: The key to add. + * + * Takes a key and stores it in the hash. + */ void addtohash(struct stats_key *key) { ++elements; diff --git a/hash.h b/hash.h index b7caa1a..284095d 100644 --- a/hash.h +++ b/hash.h @@ -23,6 +23,14 @@ */ void inithash(void); +/** + * destroyhash - Clean up the hash after use. + * + * This function destroys the hash after use, freeing any memory that was + * used during its lifetime. + */ +void destroyhash(void); + /** * addtohash - Adds a key to the hash. * @key: The key to add. -- 2.39.5