diff options
author | ntfreak <ntfreak@b42882b7-edfa-0310-969c-e2dbd0fdcd60> | 2008-12-10 17:47:16 +0000 |
---|---|---|
committer | ntfreak <ntfreak@b42882b7-edfa-0310-969c-e2dbd0fdcd60> | 2008-12-10 17:47:16 +0000 |
commit | 00b3eb5fed59b87da16590bdfd8e0c682af7c891 (patch) | |
tree | ab1719de76d505cb4eca3b53c05579975a0d7e20 | |
parent | 40042df09d51fc375706838131b1f7a36b79cb50 (diff) | |
download | openocd+libswd-00b3eb5fed59b87da16590bdfd8e0c682af7c891.tar.gz openocd+libswd-00b3eb5fed59b87da16590bdfd8e0c682af7c891.tar.bz2 openocd+libswd-00b3eb5fed59b87da16590bdfd8e0c682af7c891.tar.xz openocd+libswd-00b3eb5fed59b87da16590bdfd8e0c682af7c891.zip |
- fix illegal memory access in unregister_command function
git-svn-id: svn://svn.berlios.de/openocd/trunk@1224 b42882b7-edfa-0310-969c-e2dbd0fdcd60
-rw-r--r-- | src/helper/command.c | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/src/helper/command.c b/src/helper/command.c index cccf60e5..cba05f16 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -289,8 +289,10 @@ int unregister_command(command_context_t *context, char *name) return ERROR_INVALID_ARGUMENTS; /* find command */ - for (c = context->commands; c; c = c->next) - { + c = context->commands; + + while(NULL != c) + { if (strcmp(name, c->name) == 0) { /* unlink command */ @@ -300,26 +302,32 @@ int unregister_command(command_context_t *context, char *name) } else { + /* first element in command list */ context->commands = c->next; } - + /* unregister children */ - if (c->children) + while(NULL != c->children) { - for (c2 = c->children; c2; c2 = c2->next) - { - free(c2->name); - free(c2); - } + c2 = c->children; + c->children = c->children->next; + free(c2->name); + c2->name = NULL; + free(c2); + c2 = NULL; } - + /* delete command */ free(c->name); + c->name = NULL; free(c); + c = NULL; + return ERROR_OK; } - + /* remember the last command for unlinking */ p = c; + c = c->next; } return ERROR_OK; |