diff options
Diffstat (limited to 'lib/shash.c')
-rw-r--r-- | lib/shash.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/shash.c b/lib/shash.c index 1a85b792..c4d3ccb8 100644 --- a/lib/shash.c +++ b/lib/shash.c @@ -40,6 +40,16 @@ shash_destroy(struct shash *sh) } } +/* Like shash_destroy(), but also free() each node's 'data'. */ +void +shash_destroy_free_data(struct shash *sh) +{ + if (sh) { + shash_clear_free_data(sh); + hmap_destroy(&sh->map); + } +} + void shash_swap(struct shash *a, struct shash *b) { @@ -64,6 +74,20 @@ shash_clear(struct shash *sh) } } +/* Like shash_clear(), but also free() each node's 'data'. */ +void +shash_clear_free_data(struct shash *sh) +{ + struct shash_node *node, *next; + + SHASH_FOR_EACH_SAFE (node, next, sh) { + hmap_remove(&sh->map, &node->node); + free(node->data); + free(node->name); + free(node); + } +} + bool shash_is_empty(const struct shash *shash) { |