[gnome-shell] Don't crash on accesses to stale window-backed apps



commit db297e7fdb08e80583c39bd6c59ddf05805f67ec
Author: Owen W. Taylor <otaylor fishsoup net>
Date:   Wed Oct 7 22:56:11 2015 -0400

    Don't crash on accesses to stale window-backed apps
    
    The JS code could still be holding on to a reference to a window-backed app
    after all windows have vanished. (For example, the dash queues an idle to
    refetch apps and display them.) Avoid dying with an error message if we
    attempt to activate or otherwise manipulate such a window.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=674799

 src/shell-app.c |   31 ++++++++++++++++++++++---------
 1 files changed, 22 insertions(+), 9 deletions(-)
---
diff --git a/src/shell-app.c b/src/shell-app.c
index 4f1fe10..afc45cb 100644
--- a/src/shell-app.c
+++ b/src/shell-app.c
@@ -156,16 +156,20 @@ static MetaWindow *
 window_backed_app_get_window (ShellApp     *app)
 {
   g_assert (app->info == NULL);
-  g_assert (app->running_state);
-  g_assert (app->running_state->windows);
-  return app->running_state->windows->data;
+  if (app->running_state)
+    {
+      g_assert (app->running_state->windows);
+      return app->running_state->windows->data;
+    }
+  else
+    return NULL;
 }
 
 static ClutterActor *
 window_backed_app_get_icon (ShellApp *app,
                             int       size)
 {
-  MetaWindow *window;
+  MetaWindow *window = NULL;
   ClutterActor *actor;
   gint scale;
   ShellGlobal *global;
@@ -181,14 +185,16 @@ window_backed_app_get_icon (ShellApp *app,
    * window-backend apps, it's possible we get a request for the icon.
    * Avoid asserting here and just return an empty image.
    */
-  if (app->running_state == NULL)
+  if (app->running_state != NULL)
+    window = window_backed_app_get_window (app);
+
+  if (window == NULL)
     {
       actor = clutter_texture_new ();
       g_object_set (actor, "opacity", 0, "width", (float) size, "height", (float) size, NULL);
       return actor;
     }
 
-  window = window_backed_app_get_window (app);
   actor = st_texture_cache_bind_cairo_surface_property (st_texture_cache_get_default (),
                                                         G_OBJECT (window),
                                                         "icon");
@@ -232,9 +238,10 @@ shell_app_get_name (ShellApp *app)
   else
     {
       MetaWindow *window = window_backed_app_get_window (app);
-      const char *name;
+      const char *name = NULL;
 
-      name = meta_window_get_wm_class (window);
+      if (window)
+        name = meta_window_get_wm_class (window);
       if (!name)
         name = C_("program", "Unknown");
       return name;
@@ -1154,7 +1161,13 @@ shell_app_launch (ShellApp     *app,
   if (app->info == NULL)
     {
       MetaWindow *window = window_backed_app_get_window (app);
-      meta_window_activate (window, timestamp);
+      /* We don't use an error return if there no longer any windows, because the
+       * user attempting to activate a stale window backed app isn't something
+       * we would expect the caller to meaningfully handle or display an error
+       * message to the user.
+       */
+      if (window)
+        meta_window_activate (window, timestamp);
       return TRUE;
     }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]