From a197e759ffcb047a383adf686966f68934fef206 Mon Sep 17 00:00:00 2001 From: oharboe Date: Wed, 7 May 2008 12:15:19 +0000 Subject: [PATCH] Edgar Grimberg plugged a leak found w/Valgrind. git-svn-id: svn://svn.berlios.de/openocd/trunk@646 b42882b7-edfa-0310-969c-e2dbd0fdcd60 --- src/helper/command.c | 39 +++++++++++++++++++++++++++++++++++++++ src/helper/command.h | 1 + src/openocd.c | 2 ++ 3 files changed, 42 insertions(+) diff --git a/src/helper/command.c b/src/helper/command.c index 31666e3a..0a120b10 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -143,6 +143,45 @@ command_t* register_command(command_context_t *context, command_t *parent, char return c; } +int unregister_all_commands(command_context_t *context) +{ + command_t *c, *c2; + + unique_length_dirty = 1; + + if (context == NULL) + return ERROR_OK; + + + while(NULL != context->commands) + { + c = context->commands; + + while(NULL != c->children) + { + c2 = c->children; + c->children = c->children->next; + free(c2->name); + c2->name = NULL; + free(c2->help); + c2->help = NULL; + free(c2); + c2 = NULL; + } + + context->commands = context->commands->next; + + free(c->name); + c->name = NULL; + free(c->help); + c->help = NULL; + free(c); + c = NULL; + } + + return ERROR_OK; +} + int unregister_command(command_context_t *context, char *name) { command_t *c, *p = NULL, *c2; diff --git a/src/helper/command.h b/src/helper/command.h index 3586017d..ed6a96a7 100644 --- a/src/helper/command.h +++ b/src/helper/command.h @@ -66,6 +66,7 @@ typedef struct command_s extern command_t* register_command(command_context_t *context, command_t *parent, char *name, int (*handler)(struct command_context_s *context, char* name, char** args, int argc), enum command_mode mode, char *help); extern int unregister_command(command_context_t *context, char *name); +extern int unregister_all_commands(command_context_t *context); extern void command_set_output_handler(command_context_t* context, int (*output_handler)(struct command_context_s *context, char* line), void *priv); extern command_context_t* copy_command_context(command_context_t* context); extern command_context_t* command_init(); diff --git a/src/openocd.c b/src/openocd.c index 449736e1..946cd93c 100644 --- a/src/openocd.c +++ b/src/openocd.c @@ -225,6 +225,8 @@ int main(int argc, char *argv[]) /* shut server down */ server_quit(); + unregister_all_commands(cmd_ctx); + /* free commandline interface */ command_done(cmd_ctx); -- 2.39.5