]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MAJOR: lru: fix unconditional call to free due to unexpected semi-colon
authorWilly Tarreau <w@1wt.eu>
Wed, 17 Jun 2015 17:53:03 +0000 (19:53 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 17 Jun 2015 17:55:32 +0000 (19:55 +0200)
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.

src/lru.c

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