diff --git a/src/Db.c b/src/Db.c index 7ce6681..baf70ab 100644 --- a/src/Db.c +++ b/src/Db.c @@ -293,6 +293,7 @@ DbCacheEvict(Db * db) pthread_mutex_destroy(&ref->lock); hash = DbHashKey(ref->name); + Free(HashMapGetKey(db->cache, hash)); HashMapDelete(db->cache, hash); Free(hash); @@ -621,6 +622,7 @@ DbDelete(Db * db, size_t nArgs,...) { pthread_mutex_lock(&ref->lock); + Free(HashMapGetKey(db->cache, hash)); HashMapDelete(db->cache, hash); JsonFree(ref->json); StringArrayFree(ref->name); diff --git a/src/HashMap.c b/src/HashMap.c index 2320533..e7f246d 100644 --- a/src/HashMap.c +++ b/src/HashMap.c @@ -244,6 +244,40 @@ HashMapGet(HashMap * map, const char *key) return NULL; } +void * +HashMapGetKey(HashMap * map, const char *key) +{ + unsigned long hash; + size_t index; + + if (!map || !key) + { + return NULL; + } + + hash = map->hashFunc(key); + index = hash % map->capacity; + + for (;;) + { + HashMapBucket *bucket = map->entries[index]; + + if (!bucket) + { + break; + } + + if (bucket->hash == hash) + { + return bucket->key; + } + + index = (index + 1) % map->capacity; + } + + return NULL; +} + int HashMapIterate(HashMap * map, char **key, void **value) { diff --git a/src/include/HashMap.h b/src/include/HashMap.h index dbf2420..990ed25 100644 --- a/src/include/HashMap.h +++ b/src/include/HashMap.h @@ -42,6 +42,9 @@ extern void * extern void * HashMapGet(HashMap *, const char *); +extern void * + HashMapGetKey(HashMap *, const char *); + extern void * HashMapDelete(HashMap *, const char *);