From c705467d301e9988fb429ff40fb38655241a2655 Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Mon, 30 Jan 2023 18:06:57 +1100 Subject: [PATCH] named-rrchecker: have fatal cleanup It is trivial to fully cleanup memory on all the error paths in named-rrchecker, many of which are triggered by bad user input. This involves freeing lex and mctx if they exist when fatal is called. (cherry picked from commit dbe82813e6c6248e53055312471c556f99d046ad) --- bin/tools/named-rrchecker.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/bin/tools/named-rrchecker.c b/bin/tools/named-rrchecker.c index 2ea0ef48e4..4d8a318b5f 100644 --- a/bin/tools/named-rrchecker.c +++ b/bin/tools/named-rrchecker.c @@ -52,6 +52,17 @@ usage(void) { exit(0); } +static void +cleanup(void) { + if (lex != NULL) { + isc_lex_close(lex); + isc_lex_destroy(&lex); + } + if (mctx != NULL) { + isc_mem_destroy(&mctx); + } +} + noreturn static void fatal(const char *format, ...); @@ -64,6 +75,7 @@ fatal(const char *format, ...) { vfprintf(stderr, format, args); va_end(args); fputc('\n', stderr); + cleanup(); exit(1); } @@ -329,8 +341,6 @@ main(int argc, char *argv[]) { fflush(stdout); } - isc_lex_close(lex); - isc_lex_destroy(&lex); - isc_mem_destroy(&mctx); + cleanup(); return (0); }