cache: fix memory leak, add missing function

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui 2019-05-05 04:55:42 +01:00
parent c08fd08ea4
commit 93e4a53d48
No known key found for this signature in database
GPG Key ID: 37C999F617EA1A47
1 changed files with 9 additions and 0 deletions

View File

@ -34,6 +34,7 @@ static inline void _cache_invalidate(struct cache *c, struct cache_entry *e) {
if (c->free) {
c->free(c->user_data, e->value);
}
free(e->key);
HASH_DEL(c->entries, e);
free(e);
}
@ -60,3 +61,11 @@ void *cache_free(struct cache *c) {
free(c);
return ret;
}
struct cache *new_cache(void *ud, cache_getter_t getter, cache_free_t f) {
auto c = ccalloc(1, struct cache);
c->user_data = ud;
c->getter = getter;
c->free = f;
return c;
}