cache: fix memory leak, add missing function
Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
parent
c08fd08ea4
commit
93e4a53d48
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue