From d58c9a57c68c7f774244be88faad850ceb1a9672 Mon Sep 17 00:00:00 2001 From: "Owen W. Taylor" Date: Sat, 22 Aug 2009 15:55:17 -0400 Subject: [PATCH] Avoid accessing freed memory when being replaced If we are replaced via the window manager selection, then we close the MetaDisplay before meta_finalize() runs. We should be careful not to try to close the display again (and access already freed memory) in that case, so clear the global 'the_display' variable. See Metacity bug http://bugzilla.gnome.org/show_bug.cgi?id=588119 http://bugzilla.gnome.org/show_bug.cgi?id=592742 --- src/core/display.c | 1 + src/core/main.c | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/core/display.c b/src/core/display.c index f32ec62bd..c84673bdc 100644 --- a/src/core/display.c +++ b/src/core/display.c @@ -1007,6 +1007,7 @@ meta_display_close (MetaDisplay *display, meta_compositor_destroy (display->compositor); g_object_unref (display); + the_display = NULL; meta_quit (META_EXIT_SUCCESS); } diff --git a/src/core/main.c b/src/core/main.c index c074b74ec..7aa62c95f 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -427,8 +427,11 @@ meta_select_display (gchar *display_name) static void meta_finalize (void) { - meta_display_close (meta_get_display (), - CurrentTime); /* I doubt correct timestamps matter here */ + MetaDisplay *display = meta_get_display (); + + if (display) + meta_display_close (display, + CurrentTime); /* I doubt correct timestamps matter here */ meta_session_shutdown (); }