mirror of
https://github.com/tmate-io/tmate.git
synced 2024-11-23 08:33:17 +01:00
A similar for fix for window_choose: don't rely on the callback always being
called to free data, have a separate free callback and call it from the mode cleanup code.
This commit is contained in:
parent
65deba3a35
commit
216df07688
@ -84,7 +84,7 @@ cmd_choose_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
cdata->client = server_client_index(ctx->curclient);
|
||||
|
||||
window_choose_ready(
|
||||
wl->window->active, cur, cmd_choose_session_callback, cdata);
|
||||
wl->window->active, cur, cmd_choose_session_callback, xfree, cdata);
|
||||
|
||||
return (0);
|
||||
}
|
||||
@ -103,5 +103,4 @@ cmd_choose_session_callback(void *data, int idx)
|
||||
server_redraw_client(c);
|
||||
}
|
||||
}
|
||||
xfree(cdata);
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ cmd_choose_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
fatalx("session not found");
|
||||
|
||||
window_choose_ready(
|
||||
wl->window->active, cur, cmd_choose_window_callback, cdata);
|
||||
wl->window->active, cur, cmd_choose_window_callback, xfree, cdata);
|
||||
|
||||
return (0);
|
||||
}
|
||||
@ -102,5 +102,4 @@ cmd_choose_window_callback(void *data, int idx)
|
||||
server_redraw_session(s);
|
||||
recalculate_sizes();
|
||||
}
|
||||
xfree(cdata);
|
||||
}
|
||||
|
@ -140,7 +140,7 @@ cmd_find_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
fatalx("session not found");
|
||||
|
||||
window_choose_ready(
|
||||
wl->window->active, 0, cmd_find_window_callback, cdata);
|
||||
wl->window->active, 0, cmd_find_window_callback, xfree, cdata);
|
||||
|
||||
out:
|
||||
ARRAY_FREE(&list_idx);
|
||||
@ -161,5 +161,4 @@ cmd_find_window_callback(void *data, int idx)
|
||||
server_redraw_session(s);
|
||||
recalculate_sizes();
|
||||
}
|
||||
xfree(cdata);
|
||||
}
|
||||
|
2
tmux.h
2
tmux.h
@ -1490,7 +1490,7 @@ void window_choose_vadd(
|
||||
void printflike3 window_choose_add(
|
||||
struct window_pane *, int, const char *, ...);
|
||||
void window_choose_ready(struct window_pane *,
|
||||
u_int, void (*)(void *, int), void *);
|
||||
u_int, void (*)(void *, int), void (*)(void *), void *);
|
||||
|
||||
/* names.c */
|
||||
void set_window_names(void);
|
||||
|
@ -59,7 +59,8 @@ struct window_choose_mode_data {
|
||||
u_int top;
|
||||
u_int selected;
|
||||
|
||||
void (*callback)(void *, int);
|
||||
void (*callbackfn)(void *, int);
|
||||
void (*freefn)(void *);
|
||||
void *data;
|
||||
};
|
||||
|
||||
@ -86,8 +87,8 @@ window_choose_add(struct window_pane *wp, int idx, const char *fmt, ...)
|
||||
}
|
||||
|
||||
void
|
||||
window_choose_ready(struct window_pane *wp,
|
||||
u_int cur, void (*callback)(void *, int), void *cdata)
|
||||
window_choose_ready(struct window_pane *wp, u_int cur,
|
||||
void (*callbackfn)(void *, int), void (*freefn)(void *), void *cdata)
|
||||
{
|
||||
struct window_choose_mode_data *data = wp->modedata;
|
||||
struct screen *s = &data->screen;
|
||||
@ -96,7 +97,8 @@ window_choose_ready(struct window_pane *wp,
|
||||
if (data->selected > screen_size_y(s) - 1)
|
||||
data->top = ARRAY_LENGTH(&data->list) - screen_size_y(s);
|
||||
|
||||
data->callback = callback;
|
||||
data->callbackfn = callbackfn;
|
||||
data->freefn = freefn;
|
||||
data->data = cdata;
|
||||
|
||||
window_choose_redraw_screen(wp);
|
||||
@ -109,7 +111,11 @@ window_choose_init(struct window_pane *wp)
|
||||
struct screen *s;
|
||||
|
||||
wp->modedata = data = xmalloc(sizeof *data);
|
||||
data->callback = NULL;
|
||||
|
||||
data->callbackfn = NULL;
|
||||
data->freefn = NULL;
|
||||
data->data = NULL;
|
||||
|
||||
ARRAY_INIT(&data->list);
|
||||
data->top = 0;
|
||||
|
||||
@ -131,6 +137,9 @@ window_choose_free(struct window_pane *wp)
|
||||
struct window_choose_mode_data *data = wp->modedata;
|
||||
u_int i;
|
||||
|
||||
if (data->freefn != NULL && data->data != NULL)
|
||||
data->freefn(data->data);
|
||||
|
||||
mode_key_free(&data->mdata);
|
||||
|
||||
for (i = 0; i < ARRAY_LENGTH(&data->list); i++)
|
||||
@ -168,12 +177,12 @@ window_choose_key(struct window_pane *wp, unused struct client *c, int key)
|
||||
|
||||
switch (mode_key_lookup(&data->mdata, key)) {
|
||||
case MODEKEYCMD_QUIT:
|
||||
data->callback(data->data, -1);
|
||||
data->callbackfn(data->data, -1);
|
||||
window_pane_reset_mode(wp);
|
||||
break;
|
||||
case MODEKEYCMD_CHOOSE:
|
||||
item = &ARRAY_ITEM(&data->list, data->selected);
|
||||
data->callback(data->data, item->idx);
|
||||
data->callbackfn(data->data, item->idx);
|
||||
window_pane_reset_mode(wp);
|
||||
break;
|
||||
case MODEKEYCMD_UP:
|
||||
@ -273,7 +282,7 @@ window_choose_mouse(struct window_pane *wp,
|
||||
data->selected = idx;
|
||||
|
||||
item = &ARRAY_ITEM(&data->list, data->selected);
|
||||
data->callback(data->data, item->idx);
|
||||
data->callbackfn(data->data, item->idx);
|
||||
window_pane_reset_mode(wp);
|
||||
}
|
||||
|
||||
@ -287,7 +296,7 @@ window_choose_write_line(
|
||||
struct grid_cell gc;
|
||||
int utf8flag;
|
||||
|
||||
if (data->callback == NULL)
|
||||
if (data->callbackfn == NULL)
|
||||
fatalx("called before callback assigned");
|
||||
|
||||
utf8flag = options_get_number(&wp->window->options, "utf8");
|
||||
|
Loading…
Reference in New Issue
Block a user