Memory leaks in cmd_display_menu, from Huihui Huang.

This commit is contained in:
nicm
2026-02-23 08:50:00 +00:00
parent 50a3b4c777
commit 8c7278b53a
2 changed files with 21 additions and 16 deletions

View File

@@ -295,7 +295,7 @@ cmd_display_menu_exec(struct cmd *self, struct cmdq_item *item)
const char *border_style = args_get(args, 'S');
const char *selected_style = args_get(args, 'H');
enum box_lines lines = BOX_LINES_DEFAULT;
char *title, *cause;
char *title, *cause = NULL;
int flags = 0, starting_choice = 0;
u_int px, py, i, count = args_count(args);
struct options *o = target->s->curw->window->options;
@@ -313,8 +313,7 @@ cmd_display_menu_exec(struct cmd *self, struct cmdq_item *item)
&cause);
if (cause != NULL) {
cmdq_error(item, "starting choice %s", cause);
free(cause);
return (CMD_RETURN_ERROR);
goto fail;
}
}
}
@@ -335,8 +334,7 @@ cmd_display_menu_exec(struct cmd *self, struct cmdq_item *item)
if (count - i < 2) {
cmdq_error(item, "not enough arguments");
menu_free(menu);
return (CMD_RETURN_ERROR);
goto fail;
}
key = args_string(args, i++);
@@ -348,17 +346,13 @@ cmd_display_menu_exec(struct cmd *self, struct cmdq_item *item)
}
if (menu == NULL) {
cmdq_error(item, "invalid menu arguments");
return (CMD_RETURN_ERROR);
}
if (menu->count == 0) {
menu_free(menu);
return (CMD_RETURN_NORMAL);
goto fail;
}
if (menu->count == 0)
goto out;
if (!cmd_display_menu_get_pos(tc, item, args, &px, &py, menu->width + 4,
menu->count + 2)) {
menu_free(menu);
return (CMD_RETURN_NORMAL);
}
menu->count + 2))
goto out;
value = args_get(args, 'b');
if (value != NULL) {
@@ -367,8 +361,7 @@ cmd_display_menu_exec(struct cmd *self, struct cmdq_item *item)
&cause);
if (lines == -1) {
cmdq_error(item, "menu-border-lines %s", cause);
free(cause);
return (CMD_RETURN_ERROR);
goto fail;
}
}
@@ -380,6 +373,15 @@ cmd_display_menu_exec(struct cmd *self, struct cmdq_item *item)
style, selected_style, border_style, target, NULL, NULL) != 0)
return (CMD_RETURN_NORMAL);
return (CMD_RETURN_WAIT);
out:
menu_free(menu);
return (CMD_RETURN_NORMAL);
fail:
free(cause);
menu_free(menu);
return (CMD_RETURN_ERROR);
}
static enum cmd_retval