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.
This commit is contained in:
Willy Tarreau 2015-06-17 20:33:30 +02:00
parent ce7b4def74
commit 57b8a53f03

View File

@ -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--;