From c9621313e2699755e65d6424fd4546c33924f272 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Sat, 8 Nov 2008 23:54:16 +0100 Subject: [PATCH] Fix a couple of gengetopt-related memory leaks. It's still a bit leaky.. --- adu.c | 10 ++++++++-- select.c | 10 +++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/adu.c b/adu.c index ed1b4fa..787b0e8 100644 --- 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, ¶ms); 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; } diff --git a/select.c b/select.c index ded4a09..6b1fc93 100644 --- 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, ¶ms, &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; } -- 2.39.2