From f6c473829aefce194008a7aa6c4cd98a9ba08c4a Mon Sep 17 00:00:00 2001 From: Ray Gardner Date: Thu, 8 Aug 2024 17:47:40 -0600 Subject: [PATCH] Add awk_exit() function ASAN test showed exiting toybox awk via exit() caused a memory leak, because toybox did not have a chance to do its normal cleanup. Replace calls to exit() with awk_exit(), which sets toys.exitval and calls xexit() in toybox, but simply calls exit() in standalone wak. --- toys/pending/awk.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/toys/pending/awk.c b/toys/pending/awk.c index dfbeb247..a0183fe0 100644 --- a/toys/pending/awk.c +++ b/toys/pending/awk.c @@ -144,6 +144,11 @@ GLOBALS( } *zfiles, *cfile, *zstdout; ) +static void awk_exit(int status) +{ + toys.exitval = status; + xexit(); +} #ifdef __GNUC__ #define ATTR_FALLTHROUGH_INTENDED __attribute__ ((fallthrough)) #else @@ -356,7 +361,7 @@ static void zzerr(char *format, ...) va_end(args); if (format[strlen(format)-1] != '\n') fputc('\n', stderr); // TEMP FIXME !!! fflush(stderr); - if (fatal_sw) exit(2); + if (fatal_sw) awk_exit(2); // Don't bump error count for warnings else if (!strstr(format, "arning")) TT.cgl.compile_error_count++; } @@ -4486,7 +4491,7 @@ static void run(int optind, int argc, char **argv, char *sepstring, regfree(&TT.rx_last); free_literal_regex(); close_file(0); // close all files - if (status >= 0) exit(status); + if (status >= 0) awk_exit(status); } //////////////////// -- 2.39.2