]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: lru: fix possible memory leak when ->free() is used
authorWilly Tarreau <w@1wt.eu>
Wed, 17 Jun 2015 18:33:30 +0000 (20:33 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 17 Jun 2015 18:33:30 +0000 (20:33 +0200)
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.

src/lru.c

index 0c452623ce4654c77fb8069356c878d99f960965..4a46505f334d46b33e5456fb79460f62ee92799c 100644 (file)
--- 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--;