diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2009-07-17 07:05:59 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2009-07-17 07:05:59 +0000 |
commit | c5fbd259c753cebcffc65bfb1587452c75e3d2dc (patch) | |
tree | b41f0da68ee47d4639eddb7034453c261145036c /usr.bin | |
parent | fb46667d07def5942735f08e5a6c006ce794fbc0 (diff) |
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.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/tmux/cmd-choose-session.c | 5 | ||||
-rw-r--r-- | usr.bin/tmux/cmd-choose-window.c | 5 | ||||
-rw-r--r-- | usr.bin/tmux/cmd-find-window.c | 5 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.h | 4 | ||||
-rw-r--r-- | usr.bin/tmux/window-choose.c | 29 |
5 files changed, 27 insertions, 21 deletions
diff --git a/usr.bin/tmux/cmd-choose-session.c b/usr.bin/tmux/cmd-choose-session.c index 4c46a37b58c..91613b8f623 100644 --- a/usr.bin/tmux/cmd-choose-session.c +++ b/usr.bin/tmux/cmd-choose-session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-choose-session.c,v 1.2 2009/07/13 23:11:35 nicm Exp $ */ +/* $OpenBSD: cmd-choose-session.c,v 1.3 2009/07/17 07:05:58 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net> @@ -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); } diff --git a/usr.bin/tmux/cmd-choose-window.c b/usr.bin/tmux/cmd-choose-window.c index ed2de4d7201..7a3e7a9fece 100644 --- a/usr.bin/tmux/cmd-choose-window.c +++ b/usr.bin/tmux/cmd-choose-window.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-choose-window.c,v 1.2 2009/07/13 23:11:35 nicm Exp $ */ +/* $OpenBSD: cmd-choose-window.c,v 1.3 2009/07/17 07:05:58 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net> @@ -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); } diff --git a/usr.bin/tmux/cmd-find-window.c b/usr.bin/tmux/cmd-find-window.c index 5f1047aa58f..95dac74fb56 100644 --- a/usr.bin/tmux/cmd-find-window.c +++ b/usr.bin/tmux/cmd-find-window.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-find-window.c,v 1.3 2009/07/13 23:11:35 nicm Exp $ */ +/* $OpenBSD: cmd-find-window.c,v 1.4 2009/07/17 07:05:58 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net> @@ -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); } diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index 8afe464f34e..ba67dc05c81 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.33 2009/07/17 06:13:27 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.34 2009/07/17 07:05:58 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -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); diff --git a/usr.bin/tmux/window-choose.c b/usr.bin/tmux/window-choose.c index 81a39a9ccaa..7b6b5af4fea 100644 --- a/usr.bin/tmux/window-choose.c +++ b/usr.bin/tmux/window-choose.c @@ -1,4 +1,4 @@ -/* $OpenBSD: window-choose.c,v 1.2 2009/06/24 23:00:31 nicm Exp $ */ +/* $OpenBSD: window-choose.c,v 1.3 2009/07/17 07:05:58 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net> @@ -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"); |