]> the.earth.li Git - onak.git/blobdiff - hash.c
cscvs to tla changeset 39
[onak.git] / hash.c
diff --git a/hash.c b/hash.c
index 47ec2d8b099446fee0d033c5fad9fc15a5803e28..e131d032b576281d1ad98e478b04185e57654cf2 100644 (file)
--- a/hash.c
+++ b/hash.c
@@ -13,6 +13,7 @@
 #include "keydb.h"
 #include "keyid.h"
 #include "ll.h"
+#include "mem.h"
 #include "stats.h"
 
 /**
@@ -38,6 +39,35 @@ 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;
+
+       for (i = 0; i < HASHSIZE; i++) {
+               curll = hashtable[i];
+               /*
+                * TODO: The problem is the object has pointers that
+                * need freed too.
+                */
+               llfree(curll, free_statskey);
+               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;
@@ -109,6 +139,10 @@ struct ll *hash_getkeysigs(uint64_t keyid)
 {
        struct stats_key *key = NULL;
 
+       if (keyid == 0)  {
+               return NULL;
+       }
+
        key = findinhash(keyid);
        if (key == NULL) {
                key = malloc(sizeof(*key));