From b9972dc1567ae75c9e6e1deca0ef9a68cc61312c Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Wed, 5 Aug 2009 22:26:40 -0400 Subject: [PATCH] [command-parser] free list data in destructors The command and option lists were getting freed, but the actual commands and options weren't. --- src/libply/ply-command-parser.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/libply/ply-command-parser.c b/src/libply/ply-command-parser.c index fd77fbfa..3dbc6df9 100644 --- a/src/libply/ply-command-parser.c +++ b/src/libply/ply-command-parser.c @@ -124,9 +124,21 @@ ply_command_new (const char *name, static void ply_command_free (ply_command_t *command) { + ply_list_node_t *option_node; + if (command == NULL) return; + option_node = ply_list_get_first_node (command->options); + while (option_node != NULL) + { + ply_command_option_t *option; + + option = (ply_command_option_t *) ply_list_node_get_data (option_node); + ply_command_option_free (option); + + option_node = ply_list_get_next_node (command->options, option_node); + } ply_list_free (command->options); free (command); } @@ -341,9 +353,21 @@ ply_command_parser_new (const char *name, void ply_command_parser_free (ply_command_parser_t *command_parser) { + ply_list_node_t *command_node; + if (command_parser == NULL) return; + command_node = ply_list_get_first_node (command_parser->available_subcommands); + while (command_node != NULL) + { + ply_command_t *command; + + command = (ply_command_t *) ply_list_node_get_data (command_node); + ply_command_free (command); + + command_node = ply_list_get_next_node (command_parser->available_subcommands, command_node); + } ply_list_free (command_parser->available_subcommands); ply_list_free (command_parser->read_subcommands);