> > > Fix the memory leak? Or is that command_help_show_list() thing > freeing that parameter? > > Yep, it's a memory leak. I suppose I was a bit hasty on posting it. Here's a new version that also checks the success or failure of the alloc_printf functions. I'm trying to think of a good way to determine if no matches are found for the given match string. I'm not sure if anyone has a good idea for that since the functions being used are part of a double function recursion scheme.
On another note, I was wondering if removing the error message from the group type in helper/startup.tcl in ocd_bouncer is a reasonable idea. It looks a heck of a lot better to not have all of that error output when some one uses a group command without giving a subcommand. -- // Dean Glazeski
From 433a11f257529f14c1fd0a412a1ec578d5eee288 Mon Sep 17 00:00:00 2001 From: Dean Glazeski <[email protected]> Date: Thu, 31 Dec 2009 16:01:32 -0600 Subject: [PATCH] Fix usage/help search for subcommands. This makes it so that the usage/help command properly uses the whole command, including subcommand, in the search for help information. This previously caused erroneous output from the usage command handler. --- src/helper/command.c | 33 ++++++++++++++++++++++++++++----- 1 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/helper/command.c b/src/helper/command.c index b991544..41f502c 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -958,19 +958,42 @@ static COMMAND_HELPER(command_help_show, struct command *c, unsigned n, } COMMAND_HANDLER(handle_help_command) { + int retval; bool full = strcmp(CMD_NAME, "help") == 0; struct command *c = CMD_CTX->commands; - const char *match = ""; + char *match = NULL; + char *prev = NULL; if (CMD_ARGC == 0) match = ""; - else if (CMD_ARGC == 1) - match = CMD_ARGV[0]; - else + else if (CMD_ARGC >= 1) { + unsigned i; + for (i = 0; i < CMD_ARGC; ++i) { + if (NULL != match) { + prev = match; + match = alloc_printf("%s %s", match, CMD_ARGV[i]); + free(prev); + if (NULL == match) { + LOG_ERROR("unable to build search string"); + return -ENOMEM; + } + } else { + match = alloc_printf("%s", CMD_ARGV[i]); + if (NULL == match) { + LOG_ERROR("unable to build search string"); + return -ENOMEM; + } + } + } + } else return ERROR_COMMAND_SYNTAX_ERROR; - return CALL_COMMAND_HANDLER(command_help_show_list, c, 0, full, match); + retval = CALL_COMMAND_HANDLER(command_help_show_list, c, 0, full, match); + if (CMD_ARGC >= 1) + free(match); + + return retval; } static int command_unknown_find(unsigned argc, Jim_Obj *const *argv, -- 1.6.5.2
_______________________________________________ Openocd-development mailing list [email protected] https://lists.berlios.de/mailman/listinfo/openocd-development
