Fix from Elrond for hash table corruption. Should fix stat cache bug (I
authorJeremy Allison <jra@samba.org>
Fri, 9 Jun 2000 18:54:41 +0000 (18:54 +0000)
committerJeremy Allison <jra@samba.org>
Fri, 9 Jun 2000 18:54:41 +0000 (18:54 +0000)
sincerely hope :-). Thanks elrond !
Jeremy.

source/include/proto.h
source/lib/hash.c

index a5da95cd7dd1e94d32e9b83435f523c064f83924..9563b432fdd159e3f537e437090f2d98b355ab17 100644 (file)
@@ -106,7 +106,7 @@ int string_hash(int hash_size, const char *key);
 hash_element *hash_lookup(hash_table *table, char *key);
 hash_element *hash_insert(hash_table *table, char *value, char *key);
 void hash_remove(hash_table *table, hash_element *hash_elem);
-void hash_clear(hash_table *table);
+BOOL hash_clear(hash_table *table);
 
 /*The following definitions come from  lib/interface.c  */
 
index ccaf65b55a0e867fdf4dc2a737306d013733bdf3..cfb34a548815caff04d7f568421e4e3ab994402c 100644 (file)
@@ -61,7 +61,7 @@ BOOL hash_table_init(hash_table *table, int num_buckets, compare_function compar
        table->size = 2;
        table->comp_func = compare_func;
        while (table->size < num_buckets) 
-       table->size <<= 1;
+               table->size <<= 1;
        for (i = 0; i < NUM_PRIMES; i++) {
                if (primes[i] > table->size) {
                        table->size = primes[i];
@@ -301,7 +301,7 @@ static BOOL enlarge_hash_table(hash_table *table)
  *************************************************************************
  */
 
-void hash_clear(hash_table *table)
+BOOL hash_clear(hash_table *table)
 {
        int i;
        ubi_dlList      *bucket = table->buckets;
@@ -315,6 +315,14 @@ void hash_clear(hash_table *table)
                                free((char *)hash_elem);
                }
        }
+       table->size = 0;
        if(table->buckets)
                free((char *) table->buckets);
+       table->buckets = NULL;
+
+       /* Reinitialize the hash table. */
+       if(!hash_table_init(table, 0, table->comp_func))
+               return False;
+
+       return True;
 }