From 4c0e3f77d79a31d07f7af220ed752dc12424c58c Mon Sep 17 00:00:00 2001 From: epoch Date: Fri, 15 May 2020 08:22:34 +0000 Subject: made ll_freevalues recurse instead of using the ll_destroy if had for some reason I do not remember --- libhashtable.c | 8 ++++++-- 1 file 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;ikl;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;ikl;i++) { - ll_freevalues(ht->bucket[ht->keys[i]]->ll); + if(ht->bucket[ht->keys[i]]) { + ll_freevalues(ht->bucket[ht->keys[i]]->ll); + } } } -- cgit v1.2.3