BUG/MEDIUM: cli: prevent memory leak on write errors
authorWilly Tarreau <w@1wt.eu>
Tue, 4 May 2021 14:27:45 +0000 (16:27 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 5 May 2021 05:56:36 +0000 (07:56 +0200)
Since the introduction of payload support on the CLI in 1.9-dev1 by
commit abbf60710 ("MEDIUM: cli: Add payload support"), a chunk is
temporarily allocated for the CLI to support defragmenting a payload
passed with a command. However it's only released when passing via
the CLI_ST_END state (i.e. on clean shutdown), but not on errors.
Something as trivial as:

  $ while :; do ncat --send-only -U /path/to/cli <<< "show stat"; done

with a few hundreds of servers is enough see the number of allocated
trash chunks go through the roof in "show pools".

This needs to be backported as far as 2.0.

(cherry picked from commit 18b2a9dd874b66acca304580047fa6b3c16da1e3)
Signed-off-by: Willy Tarreau <w@1wt.eu>

src/cli.c

index 979a751..2460e53 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -704,6 +704,7 @@ static void cli_io_handler(struct appctx *appctx)
                         */
                        si_shutw(si);
                        free_trash_chunk(appctx->chunk);
+                       appctx->chunk = NULL;
                        break;
                }
                else if (appctx->st0 == CLI_ST_GETREQ) {
@@ -956,6 +957,9 @@ static void cli_io_handler(struct appctx *appctx)
  */
 static void cli_release_handler(struct appctx *appctx)
 {
+       free_trash_chunk(appctx->chunk);
+       appctx->chunk = NULL;
+
        if (appctx->io_release) {
                appctx->io_release(appctx);
                appctx->io_release = NULL;