From 569c68a8630f38431b6394be1e738ba4391bea1b Mon Sep 17 00:00:00 2001 From: Steven Wojcik Date: Fri, 23 Feb 2024 14:02:44 -0500 Subject: [PATCH] Fix leak in create_bogo_n_arg When running with ASAN and UBSAN on ubuntu 22 u00000.vtc and m00003.vtc fails from a leak from the return value of create_bogo_n_arg() in mgt_main.c. Freeing the returned value allows tests to pass. --- bin/varnishd/mgt/mgt_main.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/bin/varnishd/mgt/mgt_main.c b/bin/varnishd/mgt/mgt_main.c index c1bdaf812c3..1ea988c70cb 100644 --- a/bin/varnishd/mgt/mgt_main.c +++ b/bin/varnishd/mgt/mgt_main.c @@ -533,7 +533,7 @@ mgt_process_f_arg(struct cli *cli, unsigned C_flag, void **fap) return (retval); } -static const char * +static char * create_bogo_n_arg(void) { struct vsb *vsb; @@ -807,8 +807,11 @@ main(int argc, char * const *argv) assert(d_flag == 0 || F_flag == 0); - if (C_flag && n_arg == NULL) - n_arg = create_bogo_n_arg(); + p = NULL; + if (C_flag && n_arg == NULL) { + p = create_bogo_n_arg(); + n_arg = p; + } if (S_arg != NULL && !strcmp(S_arg, "none")) { fprintf(stderr, @@ -825,6 +828,8 @@ main(int argc, char * const *argv) workdir = VIN_n_Arg(n_arg); AN(workdir); + if (p != NULL) + free(p); if (i_arg == NULL || *i_arg == '\0') i_arg = mgt_HostName();