ipdbg: fix double free of virtual-ir data
[openocd.git] / src / helper / command.c
index 8860cf81fdd9859bede598d2f2c3ef7d3a409ea2..a775c730b88f8d5d499369b64091911531e68b17 100644 (file)
@@ -489,15 +489,29 @@ static bool command_can_run(struct command_context *cmd_ctx, struct command *c,
        return false;
 }
 
-static int run_command(struct command_context *context,
-       struct command *c, const char **words, unsigned num_words)
+static int exec_command(Jim_Interp *interp, struct command_context *context,
+               struct command *c, int argc, Jim_Obj * const *argv)
 {
+       if (c->jim_handler)
+               return c->jim_handler(interp, argc, argv);
+
+       /* use c->handler */
+       const char **words = malloc(argc * sizeof(char *));
+       if (!words) {
+               LOG_ERROR("Out of memory");
+               return JIM_ERR;
+       }
+
+       for (int i = 0; i < argc; i++)
+               words[i] = Jim_GetString(argv[i], NULL);
+
        struct command_invocation cmd = {
                .ctx = context,
                .current = c,
                .name = c->name,
-               .argc = num_words - 1,
+               .argc = argc - 1,
                .argv = words + 1,
+               .jimtcl_argv = argv + 1,
        };
 
        cmd.output = Jim_NewEmptyStringObj(context->interp);
@@ -526,7 +540,8 @@ static int run_command(struct command_context *context,
        }
        Jim_DecrRefCount(context->interp, cmd.output);
 
-       return retval;
+       free(words);
+       return command_retval_set(interp, retval);
 }
 
 int command_run_line(struct command_context *context, char *line)
@@ -867,27 +882,6 @@ static char *alloc_concatenate_strings(int argc, Jim_Obj * const *argv)
        return all;
 }
 
-static int exec_command(Jim_Interp *interp, struct command_context *cmd_ctx,
-               struct command *c, int argc, Jim_Obj * const *argv)
-{
-       if (c->jim_handler)
-               return c->jim_handler(interp, argc, argv);
-
-       /* use c->handler */
-       const char **words = malloc(argc * sizeof(char *));
-       if (!words) {
-               LOG_ERROR("Out of memory");
-               return JIM_ERR;
-       }
-
-       for (int i = 0; i < argc; i++)
-               words[i] = Jim_GetString(argv[i], NULL);
-
-       int retval = run_command(cmd_ctx, c, words, argc);
-       free(words);
-       return command_retval_set(interp, retval);
-}
-
 static int jim_command_dispatch(Jim_Interp *interp, int argc, Jim_Obj * const *argv)
 {
        /* check subcommands */

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)