=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/window.c,v retrieving revision 1.191 retrieving revision 1.192 diff -c -r1.191 -r1.192 *** src/usr.bin/tmux/window.c 2017/04/28 19:12:15 1.191 --- src/usr.bin/tmux/window.c 2017/04/28 19:13:55 1.192 *************** *** 1,4 **** ! /* $OpenBSD: window.c,v 1.191 2017/04/28 19:12:15 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott --- 1,4 ---- ! /* $OpenBSD: window.c,v 1.192 2017/04/28 19:13:55 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott *************** *** 186,196 **** { if (wl->window != NULL) { TAILQ_REMOVE(&wl->window->winlinks, wl, wentry); ! window_remove_ref(wl->window); } TAILQ_INSERT_TAIL(&w->winlinks, wl, wentry); wl->window = w; ! w->references++; } void --- 186,196 ---- { if (wl->window != NULL) { TAILQ_REMOVE(&wl->window->winlinks, wl, wentry); ! window_remove_ref(wl->window, __func__); } TAILQ_INSERT_TAIL(&w->winlinks, wl, wentry); wl->window = w; ! window_add_ref(w, __func__); } void *************** *** 200,206 **** if (w != NULL) { TAILQ_REMOVE(&w->winlinks, wl, wentry); ! window_remove_ref(w); } RB_REMOVE(winlinks, wwl, wl); --- 200,206 ---- if (w != NULL) { TAILQ_REMOVE(&w->winlinks, wl, wentry); ! window_remove_ref(w, __func__); } RB_REMOVE(winlinks, wwl, wl); *************** *** 361,368 **** static void window_destroy(struct window *w) { ! if (!TAILQ_EMPTY(&w->winlinks)) ! fatalx("window destroyed with winlinks"); RB_REMOVE(windows, &windows, w); --- 361,367 ---- static void window_destroy(struct window *w) { ! log_debug("window @%u destroyed (%d references)", w->id, w->references); RB_REMOVE(windows, &windows, w); *************** *** 387,397 **** } void ! window_remove_ref(struct window *w) { ! if (w->references == 0) ! fatal("bad reference count"); w->references--; if (w->references == 0) window_destroy(w); } --- 386,403 ---- } void ! 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) ! { w->references--; + log_debug("%s: @%u %s, now %d", __func__, w->id, from, w->references); + if (w->references == 0) window_destroy(w); }