Stop crashing when exiting windows.

This commit is contained in:
Nicholas Marriott 2007-09-21 20:45:06 +00:00
parent 70c1ba5770
commit 5ea2ac36e4
2 changed files with 9 additions and 14 deletions

View File

@ -1,4 +1,4 @@
/* $Id: session.c,v 1.14 2007-09-21 20:02:23 nicm Exp $ */ /* $Id: session.c,v 1.15 2007-09-21 20:45:05 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -129,20 +129,16 @@ session_attach(struct session *s, struct window *w)
int int
session_detach(struct session *s, struct window *w) session_detach(struct session *s, struct window *w)
{ {
if (s->window == w && session_last(s) != 0 && session_previous(s) != 0)
session_next(s);
if (s->last == w)
s->last = NULL;
window_remove(&s->windows, w); window_remove(&s->windows, w);
if (ARRAY_EMPTY(&s->windows)) { if (ARRAY_EMPTY(&s->windows)) {
session_destroy(s); session_destroy(s);
return (1); return (1);
} }
if (s->last == w)
s->last = NULL;
if (s->window == w) {
/* Reset s->window to stop it ending up in s->last. */
s->window = NULL;
if (session_last(s) != 0 && session_previous(s) != 0)
session_next(s);
}
return (0); return (0);
} }

View File

@ -1,4 +1,4 @@
/* $Id: window.c,v 1.9 2007-09-21 18:20:44 nicm Exp $ */ /* $Id: window.c,v 1.10 2007-09-21 20:45:06 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -181,9 +181,8 @@ window_remove(struct windows *ww, struct window *w)
if (window_index(ww, w, &i) != 0) if (window_index(ww, w, &i) != 0)
fatalx("window not found"); fatalx("window not found");
if (i != ARRAY_LENGTH(ww) - 1) ARRAY_SET(ww, i, NULL);
ARRAY_SET(ww, i, NULL); while (!ARRAY_EMPTY(ww) && ARRAY_LAST(ww) == NULL)
else
ARRAY_TRUNC(ww, 1); ARRAY_TRUNC(ww, 1);
w->references--; w->references--;