From 8af2590668e479acdc09a086fb125c8e15b94851 Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Tue, 10 Jun 2014 13:49:58 +0200 Subject: [PATCH] imagecache: fix memory leak (skel) --- src/imagecache.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/imagecache.c b/src/imagecache.c index aa9930a4..aa571302 100644 --- a/src/imagecache.c +++ b/src/imagecache.c @@ -60,6 +60,7 @@ typedef struct imagecache_image static int imagecache_id; static RB_HEAD(,imagecache_image) imagecache_by_id; static RB_HEAD(,imagecache_image) imagecache_by_url; +SKEL_DECLARE(imagecache_skel, imagecache_image_t); #if ENABLE_IMAGECACHE struct imagecache_config imagecache_conf; @@ -370,6 +371,7 @@ imagecache_done ( void ) free((void *)img->url); free(img); } + SKEL_FREE(imagecache_skel); } @@ -418,8 +420,7 @@ uint32_t imagecache_get_id ( const char *url ) { uint32_t id = 0; - imagecache_image_t *i; - static imagecache_image_t *skel = NULL; + imagecache_image_t *i, *j; lock_assert(&global_lock); @@ -434,18 +435,18 @@ imagecache_get_id ( const char *url ) #endif /* Skeleton */ - if (!skel) - skel = calloc(1, sizeof(imagecache_image_t)); - skel->url = url; + SKEL_ALLOC(imagecache_skel); + imagecache_skel->url = url; /* Create/Find */ - i = RB_INSERT_SORTED(&imagecache_by_url, skel, url_link, url_cmp); + i = RB_INSERT_SORTED(&imagecache_by_url, imagecache_skel, url_link, url_cmp); if (!i) { - i = skel; + i = imagecache_skel; i->url = strdup(url); i->id = ++imagecache_id; - skel = RB_INSERT_SORTED(&imagecache_by_id, i, id_link, id_cmp); - assert(!skel); + j = RB_INSERT_SORTED(&imagecache_by_id, i, id_link, id_cmp); + assert(!j); + SKEL_USED(imagecache_skel); #if ENABLE_IMAGECACHE imagecache_image_add(i); #endif