From: Jan Kiszka Date: Tue, 15 Jun 2010 22:38:33 +0000 (+0200) Subject: monitor: Fix leakage during completion processing X-Git-Tag: Tizen_Studio_1.3_Release_p2.3.1~4538^2~22 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fd072e96ba8b76e56aca53d6ee670b5b6f24ab6e;p=sdk%2Femulator%2Fqemu.git monitor: Fix leakage during completion processing Given too many arguments or an invalid command, we were leaking the duplicated argument strings. Signed-off-by: Jan Kiszka Signed-off-by: Luiz Capitulino --- diff --git a/monitor.c b/monitor.c index 170b26971f..42ae1546db 100644 --- a/monitor.c +++ b/monitor.c @@ -3882,8 +3882,9 @@ static void monitor_find_completion(const char *cmdline) next arg */ len = strlen(cmdline); if (len > 0 && qemu_isspace(cmdline[len - 1])) { - if (nb_args >= MAX_ARGS) - return; + if (nb_args >= MAX_ARGS) { + goto cleanup; + } args[nb_args++] = qemu_strdup(""); } if (nb_args <= 1) { @@ -3898,12 +3899,15 @@ static void monitor_find_completion(const char *cmdline) } } else { /* find the command */ - for(cmd = mon_cmds; cmd->name != NULL; cmd++) { - if (compare_cmd(args[0], cmd->name)) - goto found; + for (cmd = mon_cmds; cmd->name != NULL; cmd++) { + if (compare_cmd(args[0], cmd->name)) { + break; + } } - return; - found: + if (!cmd->name) { + goto cleanup; + } + ptype = next_arg_type(cmd->args_type); for(i = 0; i < nb_args - 2; i++) { if (*ptype != '\0') { @@ -3953,8 +3957,11 @@ static void monitor_find_completion(const char *cmdline) break; } } - for(i = 0; i < nb_args; i++) + +cleanup: + for (i = 0; i < nb_args; i++) { qemu_free(args[i]); + } } static int monitor_can_read(void *opaque)