From: Bruno Henc Date: Thu, 5 Nov 2026 06:28:06 +0000 (+0100) Subject: BUG/MINOR: stick-table: don't deinit the buckets of a never initialized table X-Git-Url: https://git.kaiwu.me/http/%22../$%7BGITURL%7D/static/gitweb.js?a=commitdiff_plain;h=0bf03d5d689d770b9f320b509dbfd39836518e85;p=haproxy.git BUG/MINOR: stick-table: don't deinit the buckets of a never initialized table stktable_init() is skipped for the table of a disabled proxy, so its buckets' in_bucket_toadd lists are never initialized. stktable_deinit() still calls MT_LIST_DELETE() on them when the proxy is freed, and mt_list_delete() dereferences their NULL pointers. As a result, a config with a disabled backend declaring a stick-table segfaults at the end of "haproxy -c" (exit 139) and on every graceful stop, so on every reload. Only walk the buckets once the table was initialized, which t->pool tells. The rest of the function is already safe on a never initialized table. This was introduced with the per-bucket expiration tasks in commit 8bc8a21b2 ("MEDIUM: stick-tables: Use a per-shard expiration task"), 3.3-dev11, so it must be backported to 3.3. It should fix the issue #3581. Co-Authored-By: Claude Opus 5.5 --- diff --git a/src/stick_table.c b/src/stick_table.c index 7c6a57d79..7f2a43180 100644 --- a/src/stick_table.c +++ b/src/stick_table.c @@ -1264,9 +1264,9 @@ int stktable_init(struct stktable *t, char **err_msg) return 0; } -/* Performs stick table cleanup: it's meant to be called after the table - * has been initialized ith stktable_init(), else it will lead to undefined - * behavior. +/* Performs stick table cleanup. It may be called on a table that was never + * initialized with stktable_init(), e.g. the table of a disabled proxy, which + * is skipped at init time: its buckets were never set up and are left alone. * * However it does not free the table pointer itself */ @@ -1276,7 +1276,8 @@ void stktable_deinit(struct stktable *t) if (!t) return; - for (i = 0; i < CONFIG_HAP_TBL_BUCKETS; i++) { + /* t->pool is only set once stktable_init() has set up the buckets */ + for (i = 0; t->pool && i < CONFIG_HAP_TBL_BUCKETS; i++) { HA_SPIN_LOCK(OTHER_LOCK, &per_bucket[i].lock); eb32_delete(&t->buckets[i].in_bucket); MT_LIST_DELETE(&t->buckets[i].in_bucket_toadd);