From 46361c3e289a5ba190182ec0a77b0850064f2e2c Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Sun, 13 Jul 2014 11:42:37 -0400 Subject: [PATCH] events: Return early if we close the display This is so we won't poke into the MetaDisplay, which is invalid memory, and crash. This can sometimes work right now because GSlice might not deallocate the object immediately, but it's still not a fun thing to do. --- src/x11/events.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/x11/events.c b/src/x11/events.c index 7355714f2..e031c0abc 100644 --- a/src/x11/events.c +++ b/src/x11/events.c @@ -1148,7 +1148,7 @@ process_selection_request (MetaDisplay *display, meta_verbose ("Handled selection request\n"); } -static void +static gboolean process_selection_clear (MetaDisplay *display, XEvent *event) { @@ -1169,7 +1169,7 @@ process_selection_clear (MetaDisplay *display, meta_XFree (str); - return; + return FALSE; } meta_verbose ("Got selection clear for screen %d on display %s\n", @@ -1177,6 +1177,7 @@ process_selection_clear (MetaDisplay *display, meta_display_unmanage_screen (display, display->screen, event->xselectionclear.time); + return TRUE; } static gboolean @@ -1772,13 +1773,14 @@ meta_display_handle_xevent (MetaDisplay *display, if (event->type == SelectionClear) { - /* Do this here so we can return without any further - * processing. */ - process_selection_clear (display, event); - /* Note that processing that may have resulted in - * closing the display... */ - bypass_gtk = bypass_compositor = TRUE; - goto out; + if (process_selection_clear (display, event)) + { + /* This means we called meta_display_unmanage_screen, which + * means the MetaDisplay is effectively dead. We don't want + * to poke into display->current_time below, since that would + * crash, so just directly return. */ + return TRUE; + } } out: