提交 03a63484 编写于 作者: J Jan Kiszka 提交者: Luiz Capitulino

monitor: Fix leakage during completion processing

Given too many arguments or an invalid command, we were leaking the
duplicated argument strings.
Signed-off-by: NJan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: NLuiz Capitulino <lcapitulino@redhat.com>
上级 449041d4
...@@ -3882,8 +3882,9 @@ static void monitor_find_completion(const char *cmdline) ...@@ -3882,8 +3882,9 @@ static void monitor_find_completion(const char *cmdline)
next arg */ next arg */
len = strlen(cmdline); len = strlen(cmdline);
if (len > 0 && qemu_isspace(cmdline[len - 1])) { if (len > 0 && qemu_isspace(cmdline[len - 1])) {
if (nb_args >= MAX_ARGS) if (nb_args >= MAX_ARGS) {
return; goto cleanup;
}
args[nb_args++] = qemu_strdup(""); args[nb_args++] = qemu_strdup("");
} }
if (nb_args <= 1) { if (nb_args <= 1) {
...@@ -3898,12 +3899,15 @@ static void monitor_find_completion(const char *cmdline) ...@@ -3898,12 +3899,15 @@ static void monitor_find_completion(const char *cmdline)
} }
} else { } else {
/* find the command */ /* find the command */
for(cmd = mon_cmds; cmd->name != NULL; cmd++) { for (cmd = mon_cmds; cmd->name != NULL; cmd++) {
if (compare_cmd(args[0], cmd->name)) if (compare_cmd(args[0], cmd->name)) {
goto found; break;
} }
return; }
found: if (!cmd->name) {
goto cleanup;
}
ptype = next_arg_type(cmd->args_type); ptype = next_arg_type(cmd->args_type);
for(i = 0; i < nb_args - 2; i++) { for(i = 0; i < nb_args - 2; i++) {
if (*ptype != '\0') { if (*ptype != '\0') {
...@@ -3953,8 +3957,11 @@ static void monitor_find_completion(const char *cmdline) ...@@ -3953,8 +3957,11 @@ static void monitor_find_completion(const char *cmdline)
break; break;
} }
} }
for(i = 0; i < nb_args; i++)
cleanup:
for (i = 0; i < nb_args; i++) {
qemu_free(args[i]); qemu_free(args[i]);
}
} }
static int monitor_can_read(void *opaque) static int monitor_can_read(void *opaque)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册