]> pd.if.org Git - nbds/blobdiff - struct/ht.c
free its keys too when freeing a ht
[nbds] / struct / ht.c
index 8703faa705085edeaa7bcc2e50a6eade2042e76e..aed74fae86a2462e156e04cab4209d5d45145f05 100644 (file)
@@ -517,6 +517,12 @@ hash_table_t *ht_alloc (void) {
 void ht_free (hash_table_t *ht) {
     hash_table_i_t *hti = *ht;
     do {
+        for (uint32_t i = 0; i < (1 << hti->scale); ++i) {
+            assert(hti->table[i].value == COPIED_VALUE || !IS_TAGGED(hti->table[i].value));
+            if (hti->table[i].key != DOES_NOT_EXIST) {
+                nbd_free((void *)(hti->table[i].key & MASK(48)));
+            }
+        }
         hash_table_i_t *next = hti->next;
         nbd_free(hti);
         hti = next;