From 0fea5292dd06e4532e43605cce06ff95c71e9baa Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Mon, 16 Jan 2017 16:57:21 +0200 Subject: [PATCH] lib: Add asserts to make sure hash table isn't freed while it's frozen. --- src/lib/hash.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/lib/hash.c b/src/lib/hash.c index 563588c7dd..2a2db8dfb5 100644 --- a/src/lib/hash.c +++ b/src/lib/hash.c @@ -135,6 +135,8 @@ void hash_table_destroy(struct hash_table **_table) *_table = NULL; + i_assert(table->frozen == 0); + if (!table->node_pool->alloconly_pool) { hash_table_destroy_nodes(table); destroy_node_list(table, table->free_nodes); @@ -147,6 +149,8 @@ void hash_table_destroy(struct hash_table **_table) void hash_table_clear(struct hash_table *table, bool free_nodes) { + i_assert(table->frozen == 0); + if (!table->node_pool->alloconly_pool) hash_table_destroy_nodes(table); @@ -303,6 +307,8 @@ hash_table_compress(struct hash_table *table, struct hash_node *root) { struct hash_node *node, *next; + i_assert(table->frozen == 0); + /* remove deleted nodes from the list */ for (node = root; node->next != NULL; ) { next = node->next; @@ -441,6 +447,8 @@ static bool hash_table_resize(struct hash_table *table, bool grow) unsigned int next_size, old_size, i; float nodes_per_list; + i_assert(table->frozen == 0); + nodes_per_list = (float) table->nodes_count / (float) table->size; if (nodes_per_list > 0.3 && nodes_per_list < 2.0) return FALSE; -- 2.47.3