]> git.tuebingen.mpg.de Git - adu.git/blobdiff - adu.c
Fix a couple of gengetopt-related memory leaks.
[adu.git] / adu.c
diff --git a/adu.c b/adu.c
index ed1b4fa32aee7dac5a7650f2074f8f37df2820d1..787b0e899d18cb86b20c53263603bcee735ba8ec 100644 (file)
--- a/adu.c
+++ b/adu.c
@@ -182,7 +182,6 @@ static int check_args(void)
 static int print_complete_help_and_die(void)
 {
        const char **line;
-       select_cmdline_parser_init(&select_conf);
 
        printf("%s-%s\n", CMDLINE_PARSER_PACKAGE, CMDLINE_PARSER_VERSION);
        printf("%s\n\n", gengetopt_args_info_purpose);
@@ -205,6 +204,8 @@ static int print_complete_help_and_die(void)
 
        printf("Interactive commands:\n");
        print_interactive_help();
+       cmdline_parser_free(&conf);
+       select_cmdline_parser_free(&select_conf);
        exit(EXIT_FAILURE);
 }
 
@@ -212,16 +213,19 @@ int main(int argc, char **argv)
 {
        int ret;
        struct cmdline_parser_params params = {
-               .override = 0,
+               .override = 1,
                .initialize = 1,
                .check_required = 0,
                .check_ambiguity = 0,
                .print_errors = 0
        };
+       select_cmdline_parser_init(&select_conf);
+       cmdline_parser_init(&conf);
        /* ignore errors and print complete help if --help was given */
        cmdline_parser_ext(argc, argv, &conf, &params);
        if (conf.help_given || conf.detailed_help_given)
                print_complete_help_and_die();
+       cmdline_parser_free(&conf);
        params.check_required = 1;
        params.check_ambiguity = 1;
        params.print_errors = 1;
@@ -249,5 +253,7 @@ out:
                ERROR_LOG("%s\n", adu_strerror(-ret));
                return -EXIT_FAILURE;
        }
+       cmdline_parser_free(&conf);
+       select_cmdline_parser_free(&select_conf);
        return EXIT_SUCCESS;
 }