From 51c95747d878405bcbe2077c5c27c6b1a87c48a8 Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Mon, 7 Sep 2009 21:01:50 +0000 Subject: Reference count clients and sessions rather than relying on a saved index for cmd-choose-*. --- session.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'session.c') diff --git a/session.c b/session.c index 55d38c80..4e5ac83e 100644 --- a/session.c +++ b/session.c @@ -28,6 +28,7 @@ /* Global session list. */ struct sessions sessions; +struct sessions dead_sessions; struct winlink *session_next_activity(struct session *, struct winlink *); struct winlink *session_previous_activity(struct session *, struct winlink *); @@ -121,14 +122,19 @@ session_create(const char *name, const char *cmd, const char *cwd, u_int i; s = xmalloc(sizeof *s); + s->references = 0; s->flags = 0; + if (gettimeofday(&s->tv, NULL) != 0) fatal("gettimeofday"); + s->curw = NULL; SLIST_INIT(&s->lastw); RB_INIT(&s->windows); SLIST_INIT(&s->alerts); + paste_init_stack(&s->buffers); + options_init(&s->options, &global_s_options); environ_init(&s->environ); if (env != NULL) @@ -187,7 +193,16 @@ session_destroy(struct session *s) winlink_remove(&s->windows, RB_ROOT(&s->windows)); xfree(s->name); - xfree(s); + + for (i = 0; i < ARRAY_LENGTH(&dead_sessions); i++) { + if (ARRAY_ITEM(&dead_sessions, i) == NULL) { + ARRAY_SET(&dead_sessions, i, s); + break; + } + } + if (i == ARRAY_LENGTH(&dead_sessions)) + ARRAY_ADD(&dead_sessions, s); + s->flags |= SESSION_DEAD; } /* Find session index. */ -- cgit