summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornicm <nicm@openbsd.org>2012-08-21 10:00:33 +0000
committernicm <nicm@openbsd.org>2012-08-21 10:00:33 +0000
commita3560846b7ac3804af977f8d56c2f5d1e61e00c3 (patch)
treeb08ba1620dfd97848587458439f641e17c077452
parentSort options. (diff)
downloadwireguard-openbsd-a3560846b7ac3804af977f8d56c2f5d1e61e00c3.tar.xz
wireguard-openbsd-a3560846b7ac3804af977f8d56c2f5d1e61e00c3.zip
Fix up window reference counting and don't crash if the rename timer
fires while the window is dead but still referenced. Fixes problem reported by Michael Scholz.
-rw-r--r--usr.bin/tmux/names.c5
-rw-r--r--usr.bin/tmux/notify.c5
-rw-r--r--usr.bin/tmux/tmux.h3
-rw-r--r--usr.bin/tmux/window.c21
4 files changed, 22 insertions, 12 deletions
diff --git a/usr.bin/tmux/names.c b/usr.bin/tmux/names.c
index 290946c94ab..7430a345d42 100644
--- a/usr.bin/tmux/names.c
+++ b/usr.bin/tmux/names.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: names.c,v 1.16 2012/07/10 11:53:01 nicm Exp $ */
+/* $OpenBSD: names.c,v 1.17 2012/08/21 10:00:33 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -50,6 +50,9 @@ window_name_callback(unused int fd, unused short events, void *data)
struct window *w = data;
char *name, *wname;
+ if (w->active == NULL)
+ return;
+
if (!options_get_number(&w->options, "automatic-rename")) {
if (event_initialized(&w->name_timer))
event_del(&w->name_timer);
diff --git a/usr.bin/tmux/notify.c b/usr.bin/tmux/notify.c
index ac71d5ec789..a157eb0dfd2 100644
--- a/usr.bin/tmux/notify.c
+++ b/usr.bin/tmux/notify.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: notify.c,v 1.2 2012/07/13 06:27:41 nicm Exp $ */
+/* $OpenBSD: notify.c,v 1.3 2012/08/21 10:00:33 nicm Exp $ */
/*
* Copyright (c) 2012 George Nachman <tmux@georgester.com>
@@ -125,7 +125,8 @@ notify_drain(void)
if (ne->session != NULL)
ne->session->references--;
if (ne->window != NULL)
- ne->window->references--;
+ window_remove_ref(ne->window);
+
TAILQ_REMOVE(&notify_queue, ne, entry);
free(ne);
}
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index 27791c72803..6fda58fbfe3 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.351 2012/08/14 08:51:53 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.352 2012/08/21 10:00:33 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -2130,6 +2130,7 @@ 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 winlink_clear_flags(struct winlink *);
void window_mode_attrs(struct grid_cell *, struct options *);
diff --git a/usr.bin/tmux/window.c b/usr.bin/tmux/window.c
index ff365e20169..30fb328b542 100644
--- a/usr.bin/tmux/window.c
+++ b/usr.bin/tmux/window.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: window.c,v 1.83 2012/08/11 06:45:33 nicm Exp $ */
+/* $OpenBSD: window.c,v 1.84 2012/08/21 10:00:33 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -182,13 +182,8 @@ winlink_remove(struct winlinks *wwl, struct winlink *wl)
free(wl->status_text);
free(wl);
- if (w != NULL) {
- if (w->references == 0)
- fatal("bad reference count");
- w->references--;
- if (w->references == 0)
- window_destroy(w);
- }
+ if (w != NULL)
+ window_remove_ref(w);
}
struct winlink *
@@ -363,6 +358,16 @@ window_destroy(struct window *w)
}
void
+window_remove_ref(struct window *w)
+{
+ if (w->references == 0)
+ fatal("bad reference count");
+ w->references--;
+ if (w->references == 0)
+ window_destroy(w);
+}
+
+void
window_set_name(struct window *w, const char *new_name)
{
free(w->name);