diff --git a/server/core/dbusers.c b/server/core/dbusers.c index 6748a1437..cfe2d2027 100644 --- a/server/core/dbusers.c +++ b/server/core/dbusers.c @@ -210,7 +210,7 @@ HASHTABLE *oldresources; oldusers = service->users; /* digest compare */ - if (memcmp(oldusers->cksum, newusers->cksum, SHA_DIGEST_LENGTH) == 0) { + if (oldusers && memcmp(oldusers->cksum, newusers->cksum, SHA_DIGEST_LENGTH) == 0) { /* same data, nothing to do */ LOGIF(LD, (skygw_log_write_flush( LOGFILE_DEBUG, @@ -234,7 +234,7 @@ HASHTABLE *oldresources; spinlock_release(&service->spin); - if (i) { + if (i && oldusers) { /* free the old table */ users_free(oldusers); } diff --git a/server/core/hashtable.c b/server/core/hashtable.c index df88ac9f7..c43b76916 100644 --- a/server/core/hashtable.c +++ b/server/core/hashtable.c @@ -170,6 +170,9 @@ hashtable_free(HASHTABLE *table) int i; HASHENTRIES *entry, *ptr; + if(table == NULL) + return; + hashtable_write_lock(table); for (i = 0; i < table->hashsize; i++) { @@ -235,7 +238,7 @@ hashtable_add(HASHTABLE *table, void *key, void *value) unsigned int hashkey; HASHENTRIES *entry; - if (key == NULL || value == NULL) + if (table == NULL || key == NULL || value == NULL) return 0; if (table->hashsize <= 0) { @@ -308,9 +311,13 @@ hashtable_add(HASHTABLE *table, void *key, void *value) int hashtable_delete(HASHTABLE *table, void *key) { -unsigned int hashkey = table->hashfn(key) % table->hashsize; +unsigned int hashkey; HASHENTRIES *entry, *ptr; + if(table == NULL || key == NULL) + return 0; + + hashkey = table->hashfn(key) % table->hashsize; hashtable_write_lock(table); entry = table->entries[hashkey % table->hashsize]; while (entry && entry->key && table->cmpfn(key, entry->key) != 0) @@ -369,9 +376,13 @@ HASHENTRIES *entry, *ptr; void * hashtable_fetch(HASHTABLE *table, void *key) { -unsigned int hashkey = table->hashfn(key) % table->hashsize; +unsigned int hashkey; HASHENTRIES *entry; + if(table == NULL || key == NULL) + return NULL; + + hashkey = table->hashfn(key) % table->hashsize; hashtable_read_lock(table); entry = table->entries[hashkey % table->hashsize]; while (entry && entry->key && table->cmpfn(key, entry->key) != 0) @@ -401,6 +412,9 @@ hashtable_stats(HASHTABLE *table) int total, longest, i, j; HASHENTRIES *entries; + if(table == NULL) + return; + printf("Hashtable: %p, size %d\n", table, table->hashsize); total = 0; longest = 0; @@ -606,6 +620,9 @@ hashtable_next(HASHITERATOR *iter) int i; HASHENTRIES *entries; + if(iter == NULL) + return NULL; + iter->depth++; while (iter->chain < iter->table->hashsize) {