changeset 21412:7ff9bc554381

lib: Add asserts to make sure hash table isn't freed while it's frozen.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Mon, 16 Jan 2017 16:57:21 +0200
parents f6a0e597bc41
children 91187182279c
files src/lib/hash.c
diffstat 1 files changed, 8 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib/hash.c	Mon Jan 16 23:55:17 2017 +0200
+++ b/src/lib/hash.c	Mon Jan 16 16:57:21 2017 +0200
@@ -129,6 +129,8 @@
 
 	*_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);
@@ -141,6 +143,8 @@
 
 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);
 
@@ -296,6 +300,8 @@
 {
 	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;
@@ -434,6 +440,8 @@
 	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;