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.
This commit is contained in:
Willy Tarreau 2015-06-17 19:53:03 +02:00
parent 666f504906
commit 7810ad7d59

View File

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