]> git.tuebingen.mpg.de Git - adu.git/commitdiff
Fix a couple of gengetopt-related memory leaks.
authorAndre Noll <maan@systemlinux.org>
Sat, 8 Nov 2008 22:54:16 +0000 (23:54 +0100)
committerAndre Noll <maan@systemlinux.org>
Sat, 8 Nov 2008 22:54:16 +0000 (23:54 +0100)
It's still a bit leaky..

adu.c
select.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;
 }
index ded4a095ca751574bbfa9153d3ec61ad7aa32bb2..6b1fc93f7f2464b32cbb27620408c5504b60d05f 100644 (file)
--- a/select.c
+++ b/select.c
@@ -799,12 +799,12 @@ int com_select(void)
                .print_errors = 1
        };
 
-       select_cmdline_parser_init(&select_conf);
        ret = parse_select_options(conf.select_options_arg, &params,
                &admissible_uids, &fi);
-       if (ret <= 0) /* do not run query if help was given */
-               return ret;
-       ret = run_select_query(admissible_uids, fi);
-       free_format_info(fi);
+       if (ret > 0) {
+               ret = run_select_query(admissible_uids, fi);
+               free_format_info(fi);
+       }
+       select_cmdline_parser_free(&select_conf);
        return ret;
 }