From: Willy Tarreau Date: Wed, 17 Jun 2015 18:33:30 +0000 (+0200) Subject: BUG/MEDIUM: lru: fix possible memory leak when ->free() is used X-Git-Tag: v1.6-dev3~48 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=57b8a53f03bc8a442fa3d90f9d763439912e31bb;p=thirdparty%2Fhaproxy.git BUG/MEDIUM: lru: fix possible memory leak when ->free() is used Commit 7810ad7 ("BUG/MAJOR: lru: fix unconditional call to free due to unexpected semi-colon") was not enough, it happens that the free() is not performed at the right place because if the evicted node is recycled, we must also release its data before it gets overwritten. No backport is needed. --- diff --git a/src/lru.c b/src/lru.c index 0c452623ce..4a46505f33 100644 --- a/src/lru.c +++ b/src/lru.c @@ -127,11 +127,11 @@ struct lru64 *lru64_get(unsigned long long key, struct lru64_head *lru, /* not locked */ LIST_DEL(&old->lru); __eb64_delete(&old->node); + if (old->data && old->free) + old->free(old->data); if (!lru->spare) lru->spare = old; else { - if (old->data && old->free) - old->free(old->data); free(old); } lru->cache_usage--;