summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornicm <nicm>2017-04-28 19:13:55 +0000
committernicm <nicm>2017-04-28 19:13:55 +0000
commit0f2f783584c62879a1182972e915f550bf23f00a (patch)
treea516d196841ac2f8e478e068a2a7e3c946f7a186
parentbcd6b416749cbac712c29ee07049e98c5930c800 (diff)
Log what is happening with window and session reference counts much more
obviously.
-rw-r--r--alerts.c4
-rw-r--r--notify.c14
-rw-r--r--session.c16
-rw-r--r--tmux.h6
-rw-r--r--window-choose.c4
-rw-r--r--window.c22
6 files changed, 41 insertions, 25 deletions
diff --git a/alerts.c b/alerts.c
index f4a3520c..6696369f 100644
--- a/alerts.c
+++ b/alerts.c
@@ -64,7 +64,7 @@ alerts_callback(__unused int fd, __unused short events, __unused void *arg)
TAILQ_REMOVE(&alerts_list, w, alerts_entry);
w->flags &= ~WINDOW_ALERTFLAGS;
- window_remove_ref(w);
+ window_remove_ref(w, __func__);
}
alerts_fired = 0;
}
@@ -148,7 +148,7 @@ alerts_queue(struct window *w, int flags)
if (!w->alerts_queued) {
w->alerts_queued = 1;
TAILQ_INSERT_TAIL(&alerts_list, w, alerts_entry);
- w->references++;
+ window_add_ref(w, __func__);
}
if (!alerts_fired) {
diff --git a/notify.c b/notify.c
index a338c57c..78278e09 100644
--- a/notify.c
+++ b/notify.c
@@ -101,12 +101,12 @@ notify_callback(struct cmdq_item *item, void *data)
if (ne->client != NULL)
server_client_unref(ne->client);
if (ne->session != NULL)
- session_unref(ne->session);
+ session_remove_ref(ne->session, __func__);
if (ne->window != NULL)
- window_remove_ref(ne->window);
+ window_remove_ref(ne->window, __func__);
if (ne->fs.s != NULL)
- session_unref(ne->fs.s);
+ session_remove_ref(ne->fs.s, __func__);
free((void *)ne->name);
free(ne);
@@ -136,13 +136,13 @@ notify_add(const char *name, struct cmd_find_state *fs, struct client *c,
if (c != NULL)
c->references++;
if (s != NULL)
- s->references++;
+ session_add_ref(s, __func__);
if (w != NULL)
- w->references++;
+ window_add_ref(w, __func__);
cmd_find_copy_state(&ne->fs, fs);
- if (ne->fs.s != NULL)
- ne->fs.s->references++; /* cmd_find_valid_state need session */
+ if (ne->fs.s != NULL) /* cmd_find_valid_state needs session */
+ session_add_ref(ne->fs.s, __func__);
new_item = cmdq_get_callback(notify_callback, ne);
cmdq_append(NULL, new_item);
diff --git a/session.c b/session.c
index eee478dd..ca8215ee 100644
--- a/session.c
+++ b/session.c
@@ -189,13 +189,21 @@ session_create(const char *prefix, const char *name, int argc, char **argv,
return (s);
}
-/* Remove a reference from a session. */
+/* Add a reference to a session. */
void
-session_unref(struct session *s)
+session_add_ref(struct session *s, const char *from)
{
- log_debug("session %s has %d references", s->name, s->references);
+ s->references++;
+ log_debug("%s: %s %s, now %d", __func__, s->name, from, s->references);
+}
+/* Remove a reference from a session. */
+void
+session_remove_ref(struct session *s, const char *from)
+{
s->references--;
+ log_debug("%s: %s %s, now %d", __func__, s->name, from, s->references);
+
if (s->references == 0)
event_once(-1, EV_TIMEOUT, session_free, s, NULL);
}
@@ -248,7 +256,7 @@ session_destroy(struct session *s)
free((void *)s->cwd);
- session_unref(s);
+ session_remove_ref(s, __func__);
}
/* Check a session name is valid: not empty and no colons or periods. */
diff --git a/tmux.h b/tmux.h
index 7e6f9b14..33f7f4e3 100644
--- a/tmux.h
+++ b/tmux.h
@@ -2112,7 +2112,8 @@ struct window_pane *window_pane_find_down(struct window_pane *);
struct window_pane *window_pane_find_left(struct window_pane *);
struct window_pane *window_pane_find_right(struct window_pane *);
void window_set_name(struct window *, const char *);
-void window_remove_ref(struct window *);
+void window_add_ref(struct window *, const char *);
+void window_remove_ref(struct window *, const char *);
void winlink_clear_flags(struct winlink *);
int winlink_shuffle_up(struct session *, struct winlink *);
@@ -2226,7 +2227,8 @@ struct session *session_create(const char *, const char *, int, char **,
const char *, const char *, struct environ *,
struct termios *, int, u_int, u_int, char **);
void session_destroy(struct session *);
-void session_unref(struct session *);
+void session_add_ref(struct session *, const char *);
+void session_remove_ref(struct session *, const char *);
int session_check_name(const char *);
void session_update_activity(struct session *, struct timeval *);
struct session *session_next_session(struct session *);
diff --git a/window-choose.c b/window-choose.c
index b736c5b1..c3c5f921 100644
--- a/window-choose.c
+++ b/window-choose.c
@@ -225,10 +225,10 @@ static void
window_choose_data_free(struct window_choose_data *wcd)
{
server_client_unref(wcd->start_client);
- session_unref(wcd->start_session);
+ session_remove_ref(wcd->start_session, __func__);
if (wcd->tree_session != NULL)
- session_unref(wcd->tree_session);
+ session_remove_ref(wcd->tree_session, __func__);
free(wcd->ft_template);
format_free(wcd->ft);
diff --git a/window.c b/window.c
index 1f697fac..029e4689 100644
--- a/window.c
+++ b/window.c
@@ -186,11 +186,11 @@ winlink_set_window(struct winlink *wl, struct window *w)
{
if (wl->window != NULL) {
TAILQ_REMOVE(&wl->window->winlinks, wl, wentry);
- window_remove_ref(wl->window);
+ window_remove_ref(wl->window, __func__);
}
TAILQ_INSERT_TAIL(&w->winlinks, wl, wentry);
wl->window = w;
- w->references++;
+ window_add_ref(w, __func__);
}
void
@@ -200,7 +200,7 @@ winlink_remove(struct winlinks *wwl, struct winlink *wl)
if (w != NULL) {
TAILQ_REMOVE(&w->winlinks, wl, wentry);
- window_remove_ref(w);
+ window_remove_ref(w, __func__);
}
RB_REMOVE(winlinks, wwl, wl);
@@ -361,8 +361,7 @@ window_create_spawn(const char *name, int argc, char **argv, const char *path,
static void
window_destroy(struct window *w)
{
- if (!TAILQ_EMPTY(&w->winlinks))
- fatalx("window destroyed with winlinks");
+ log_debug("window @%u destroyed (%d references)", w->id, w->references);
RB_REMOVE(windows, &windows, w);
@@ -387,11 +386,18 @@ window_destroy(struct window *w)
}
void
-window_remove_ref(struct window *w)
+window_add_ref(struct window *w, const char *from)
+{
+ w->references++;
+ log_debug("%s: @%u %s, now %d", __func__, w->id, from, w->references);
+}
+
+void
+window_remove_ref(struct window *w, const char *from)
{
- if (w->references == 0)
- fatal("bad reference count");
w->references--;
+ log_debug("%s: @%u %s, now %d", __func__, w->id, from, w->references);
+
if (w->references == 0)
window_destroy(w);
}