Fix a crash when opening two terminal windows and closing the first one.
authorDima Ryazanov <dima@gmail.com>
Thu, 29 Nov 2012 08:27:09 +0000 (00:27 -0800)
committerKristian Høgsberg <krh@bitplanet.net>
Fri, 30 Nov 2012 20:01:14 +0000 (15:01 -0500)
To reproduce, launch the terminal, open a second window using Ctrl-Shift-N,
go back to the first window, and press Ctrl-D. The terminal's master FD gets
events even after being closed, causing terminal_destroy to be called twice
on the same object.

To fix this, I'm adding a function to stop watching an FD.

clients/terminal.c
clients/window.c
clients/window.h

index 1887829..25acc81 100644 (file)
@@ -2578,13 +2578,15 @@ terminal_create(struct display *display)
 static void
 terminal_destroy(struct terminal *terminal)
 {
+       display_unwatch_fd(terminal->display, terminal->master);
        window_destroy(terminal->window);
        close(terminal->master);
        wl_list_remove(&terminal->link);
-       free(terminal);
 
        if (wl_list_empty(&terminal_list))
-               exit(0);
+               display_exit(terminal->display);
+
+       free(terminal);
 }
 
 static void
index 288a526..b7abfc8 100644 (file)
@@ -4123,6 +4123,12 @@ display_watch_fd(struct display *display,
 }
 
 void
+display_unwatch_fd(struct display *display, int fd)
+{
+       epoll_ctl(display->epoll_fd, EPOLL_CTL_DEL, fd, NULL);
+}
+
+void
 display_run(struct display *display)
 {
        struct task *task;
index 84846ff..edf8c6a 100644 (file)
@@ -147,6 +147,9 @@ display_watch_fd(struct display *display,
                 int fd, uint32_t events, struct task *task);
 
 void
+display_unwatch_fd(struct display *display, int fd);
+
+void
 display_run(struct display *d);
 
 void