]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: map/cli: always detach the backref from the list after "show map"
authorWilly Tarreau <w@1wt.eu>
Tue, 3 May 2022 13:42:07 +0000 (15:42 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 6 May 2022 16:13:35 +0000 (18:13 +0200)
There's no point checking the state before deciding to detach the backref
on "show map", it should always be done if the list is not empty. Note
that being empty guarantees that it's not linked into the list, and
conversely not being empty guarantees that it's in the list, hence the
test doesn't need to be performed under the lock.

src/map.c

index fea9a1da177336bcee7bd563e21939a8716778c1..dea9bcdfddc1a7a26652490c52e4e105aba2c114 100644 (file)
--- a/src/map.c
+++ b/src/map.c
@@ -352,12 +352,9 @@ static int cli_io_handler_pat_list(struct appctx *appctx)
                /* If we're forced to shut down, we might have to remove our
                 * reference to the last ref_elt being dumped.
                 */
-               if (ctx->state == STATE_LIST) {
+               if (!LIST_ISEMPTY(&ctx->bref.users)) {
                        HA_SPIN_LOCK(PATREF_LOCK, &ctx->ref->lock);
-                       if (!LIST_ISEMPTY(&ctx->bref.users)) {
-                               LIST_DELETE(&ctx->bref.users);
-                               LIST_INIT(&ctx->bref.users);
-                       }
+                       LIST_DEL_INIT(&ctx->bref.users);
                        HA_SPIN_UNLOCK(PATREF_LOCK, &ctx->ref->lock);
                }
                return 1;
@@ -687,10 +684,9 @@ static void cli_release_show_map(struct appctx *appctx)
 {
        struct show_map_ctx *ctx = appctx->svcctx;
 
-       if (ctx->state == STATE_LIST) {
+       if (!LIST_ISEMPTY(&ctx->bref.users)) {
                HA_SPIN_LOCK(PATREF_LOCK, &ctx->ref->lock);
-               if (!LIST_ISEMPTY(&ctx->bref.users))
-                       LIST_DELETE(&ctx->bref.users);
+               LIST_DEL_INIT(&ctx->bref.users);
                HA_SPIN_UNLOCK(PATREF_LOCK, &ctx->ref->lock);
        }
 }