From: Willy Tarreau Date: Wed, 17 Jun 2015 17:53:03 +0000 (+0200) Subject: BUG/MAJOR: lru: fix unconditional call to free due to unexpected semi-colon X-Git-Tag: v1.6-dev3~51 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7810ad7;p=thirdparty%2Fhaproxy.git BUG/MAJOR: lru: fix unconditional call to free due to unexpected semi-colon Dmitry Sivachenko reported the following build warning using Clang, which is a real bug : src/lru.c:133:32: warning: if statement has empty body [-Wempty-body] if (old->data && old->free); ^ It results in calling old->free(old->data) even when old->free is NULL, hence crashing on cached patterns. The same bug appears a few lines below in lru64_destroy() : src/lru.c:195:33: warning: if statement has empty body [-Wempty-body] if (elem->data && elem->free); ^ Both were introduced in 1.6-dev2 with commit f90ac55 ("MINOR: lru: Add the possibility to free data when an item is removed"), so no backport is needed. --- diff --git a/src/lru.c b/src/lru.c index 273f3a8863..0c452623ce 100644 --- a/src/lru.c +++ b/src/lru.c @@ -130,7 +130,7 @@ struct lru64 *lru64_get(unsigned long long key, struct lru64_head *lru, if (!lru->spare) lru->spare = old; else { - if (old->data && old->free); + if (old->data && old->free) old->free(old->data); free(old); } @@ -192,7 +192,7 @@ int lru64_destroy(struct lru64_head *lru) /* not locked */ LIST_DEL(&elem->lru); eb64_delete(&elem->node); - if (elem->data && elem->free); + if (elem->data && elem->free) elem->free(elem->data); free(elem); lru->cache_usage--;