From 25e7794f8fefe48f9d1a7c78b0c162efbb81f29a Mon Sep 17 00:00:00 2001 From: Yuxuan Shui Date: Sun, 5 May 2019 04:55:42 +0100 Subject: [PATCH] cache: fix memory leak, add missing function Signed-off-by: Yuxuan Shui --- src/cache.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/cache.c b/src/cache.c index 69ba64d1..e455032f 100644 --- a/src/cache.c +++ b/src/cache.c @@ -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; +}