diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2009-09-07 21:01:51 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2009-09-07 21:01:51 +0000 |
commit | 6347ae1b8c27e6d1e8aed4018e7dfc9017cf477b (patch) | |
tree | aa27d40b77e3f0e9cb14df5111f38bf7b765b815 /usr.bin/tmux/cmd-choose-session.c | |
parent | 211fbc439442169315739837a03a8a12528f1b10 (diff) |
Reference count clients and sessions rather than relying on a saved index for
cmd-choose-*.
Diffstat (limited to 'usr.bin/tmux/cmd-choose-session.c')
-rw-r--r-- | usr.bin/tmux/cmd-choose-session.c | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/usr.bin/tmux/cmd-choose-session.c b/usr.bin/tmux/cmd-choose-session.c index 659f18a2248..170ba142baf 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.6 2009/08/25 13:32:14 nicm Exp $ */ +/* $OpenBSD: cmd-choose-session.c,v 1.7 2009/09/07 21:01:50 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net> @@ -43,7 +43,7 @@ const struct cmd_entry cmd_choose_session_entry = { }; struct cmd_choose_session_data { - u_int client; + struct client *client; char *template; }; @@ -87,7 +87,8 @@ cmd_choose_session_exec(struct cmd *self, struct cmd_ctx *ctx) cdata->template = xstrdup(data->arg); else cdata->template = xstrdup("switch-client -t '%%'"); - cdata->client = server_client_index(ctx->curclient); + cdata->client = ctx->curclient; + cdata->client->references++; window_choose_ready(wl->window->active, cur, cmd_choose_session_callback, cmd_choose_session_free, cdata); @@ -99,7 +100,6 @@ void cmd_choose_session_callback(void *data, int idx) { struct cmd_choose_session_data *cdata = data; - struct client *c; struct session *s; struct cmd_list *cmdlist; struct cmd_ctx ctx; @@ -107,9 +107,8 @@ cmd_choose_session_callback(void *data, int idx) if (idx == -1) return; - if (cdata->client > ARRAY_LENGTH(&clients) - 1) + if (cdata->client->flags & CLIENT_DEAD) return; - c = ARRAY_ITEM(&clients, cdata->client); if ((u_int) idx > ARRAY_LENGTH(&sessions) - 1) return; @@ -121,7 +120,7 @@ cmd_choose_session_callback(void *data, int idx) if (cmd_string_parse(template, &cmdlist, &cause) != 0) { if (cause != NULL) { *cause = toupper((u_char) *cause); - status_message_set(c, "%s", cause); + status_message_set(cdata->client, "%s", cause); xfree(cause); } xfree(template); @@ -130,7 +129,7 @@ cmd_choose_session_callback(void *data, int idx) xfree(template); ctx.msgdata = NULL; - ctx.curclient = c; + ctx.curclient = cdata->client; ctx.error = key_bindings_error; ctx.print = key_bindings_print; @@ -147,6 +146,7 @@ cmd_choose_session_free(void *data) { struct cmd_choose_session_data *cdata = data; + cdata->client->references--; xfree(cdata->template); xfree(cdata); } |