summaryrefslogtreecommitdiffstats
path: root/session.c
diff options
context:
space:
mode:
authorThomas Adam <thomas@xteddy.org>2015-06-07 23:42:25 +0100
committerThomas Adam <thomas@xteddy.org>2015-06-07 23:42:25 +0100
commit7acc4addb51c711afed3761302c2d3457125445c (patch)
tree03cca6f3242974dba6adc2c1d1b721a595d24a37 /session.c
parenta5c55e439383202547e442f6afc0c8c664687728 (diff)
parentc4e811e51936edab66803a7b9e099ac135e6e19b (diff)
Merge branch 'obsd-master'
Conflicts: client.c tmux.1 tmux.c
Diffstat (limited to 'session.c')
-rw-r--r--session.c31
1 files changed, 27 insertions, 4 deletions
diff --git a/session.c b/session.c
index 0780ec3f..e0d06ec9 100644
--- a/session.c
+++ b/session.c
@@ -26,12 +26,12 @@
#include "tmux.h"
-/* Global session list. */
struct sessions sessions;
-struct sessions dead_sessions;
u_int next_session_id;
struct session_groups session_groups;
+void session_free(int, short, void *);
+
struct winlink *session_next_alert(struct winlink *);
struct winlink *session_previous_alert(struct winlink *);
@@ -108,7 +108,7 @@ session_create(const char *name, int argc, char **argv, const char *path,
struct winlink *wl;
s = xmalloc(sizeof *s);
- s->references = 0;
+ s->references = 1;
s->flags = 0;
if (gettimeofday(&s->creation_time, NULL) != 0)
@@ -163,6 +163,29 @@ session_create(const char *name, int argc, char **argv, const char *path,
return (s);
}
+/* Remove a reference from a session. */
+void
+session_unref(struct session *s)
+{
+ log_debug("session %s has %d references", s->name, s->references);
+
+ s->references--;
+ if (s->references == 0)
+ event_once(-1, EV_TIMEOUT, session_free, s, NULL);
+}
+
+/* Free session. */
+void
+session_free(unused int fd, unused short events, void *arg)
+{
+ struct session *s = arg;
+
+ log_debug("sesson %s freed (%d references)", s->name, s->references);
+
+ if (s->references == 0)
+ free(s);
+}
+
/* Destroy a session. */
void
session_destroy(struct session *s)
@@ -190,7 +213,7 @@ session_destroy(struct session *s)
close(s->cwd);
- RB_INSERT(sessions, &dead_sessions, s);
+ session_unref(s);
}
/* Check a session name is valid: not empty and no colons or periods. */