]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: Add asserts to make sure hash table isn't freed while it's frozen.
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 16 Jan 2017 14:57:21 +0000 (16:57 +0200)
committerGitLab <gitlab@git.dovecot.net>
Tue, 17 Jan 2017 11:29:44 +0000 (13:29 +0200)
src/lib/hash.c

index 563588c7ddb7f6ec9fd87ccbd2130625a3e4a393..2a2db8dfb552cfa10d1cb3b6e9878b37eb57017f 100644 (file)
@@ -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;