]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
named-rrchecker: have fatal cleanup
authorMark Andrews <marka@isc.org>
Mon, 30 Jan 2023 07:06:57 +0000 (18:06 +1100)
committerMark Andrews <marka@isc.org>
Mon, 6 Feb 2023 23:29:12 +0000 (23:29 +0000)
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.

bin/tools/named-rrchecker.c

index ce4a948343afea9c23c268e85cbd3e5808d1d86c..46794b9f796d7608427ec410a73fd63954d87560 100644 (file)
@@ -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);
 }