diff options
author | epoch <epoch@hack.thebackupbox.net> | 2020-05-15 08:22:34 +0000 |
---|---|---|
committer | epoch <epoch@hack.thebackupbox.net> | 2020-05-15 08:22:34 +0000 |
commit | 4c0e3f77d79a31d07f7af220ed752dc12424c58c (patch) | |
tree | 02df6ce50c1f56a4376c38265140f21ff5c44ee3 | |
parent | a6c1f8c35263b3d94acfe6e187c8d993aba0cff1 (diff) | |
download | libhashtable-4c0e3f77d79a31d07f7af220ed752dc12424c58c.tar.gz libhashtable-4c0e3f77d79a31d07f7af220ed752dc12424c58c.zip |
made ll_freevalues recurse instead of using the ll_destroy if had for some reason I do not remember
-rw-r--r-- | libhashtable.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/libhashtable.c b/libhashtable.c index ddb7fb0..f333c24 100644 --- a/libhashtable.c +++ b/libhashtable.c @@ -144,6 +144,7 @@ void ll_destroy(struct entry *ll) { free(ll); } +//this is to just free the buckets and the linked list structs void ht_destroy(struct hashtable *ht) { int i=0; for(i=0;i<ht->kl;i++) { @@ -153,14 +154,17 @@ void ht_destroy(struct hashtable *ht) { } void ll_freevalues(struct entry *ll) {//only use if you malloc your table. - if(ll->next) ll_destroy(ll->next); + if(!ll) return; + if(ll->next) ll_freevalues(ll->next); free(ll->target); } void ht_freevalues(struct hashtable *ht) { int i; for(i=0;i<ht->kl;i++) { - ll_freevalues(ht->bucket[ht->keys[i]]->ll); + if(ht->bucket[ht->keys[i]]) { + ll_freevalues(ht->bucket[ht->keys[i]]->ll); + } } } |