-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathn_hash_free.c
53 lines (41 loc) · 940 Bytes
/
n_hash_free.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "n_hash_int.h"
static
void free_slot(struct hash_bucket *node, tn_hash *ht)
{
register struct hash_bucket *next_node;
for (; node != NULL; node = next_node) {
next_node = node->next;
if (ht->free_fn != NULL && node->data != NULL) {
DBGF("free %s %p\n", node->key, node->data);
ht->free_fn(node->data);
}
if (ht->na == NULL)
free(node);
}
}
void n_hash_free(tn_hash *ht)
{
size_t i;
if (ht->_refcnt > 0) {
ht->_refcnt--;
return;
}
#if ENABLE_TRACE
n_hash_stats(ht);
#endif
for (i = 0; i < ht->size; i++) {
if (ht->table[i])
free_slot(ht->table[i], ht);
}
free(ht->table);
ht->table = NULL;
ht->size = 0;
ht->items = 0;
if (ht->na == NULL)
free(ht);
else
n_alloc_free(ht->na);
}