Deal with startup notify id being NULL
authorMatthias Clasen <mclasen@redhat.com>
Fri, 11 Apr 2014 22:46:38 +0000 (15:46 -0700)
committerMatthias Clasen <mclasen@redhat.com>
Sat, 12 Apr 2014 02:00:12 +0000 (19:00 -0700)
The app launch context may just not support startup notification,
in which case, g_app_launch_context_get_startup_notify_id() will
return NULL.

Failure to take this into account leads to criticals like this:
gnome-session[8489]: GLib-CRITICAL: g_variant_new_take_string: assertion 'string != NULL' failed
gnome-session[8489]: GLib-CRITICAL: g_variant_new_variant: assertion 'value != NULL' failed
gnome-session[8489]: GLib-CRITICAL: g_variant_get_type: assertion 'value != NULL' failed
gnome-session[8489]: GLib-CRITICAL: g_variant_type_is_subtype_of: assertion 'g_variant_type_check (type)' failed

https://bugzilla.gnome.org/show_bug.cgi?id=728066

gio/gdesktopappinfo.c

index 0582b52..7cf3cc0 100644 (file)
@@ -2182,7 +2182,11 @@ g_desktop_app_info_launch_uris_with_spawn (GDesktopAppInfo            *info,
               sn_id = g_app_launch_context_get_startup_notify_id (launch_context,
                                                                   G_APP_INFO (info),
                                                                   launched_files);
-              envp = g_environ_setenv (envp, "DESKTOP_STARTUP_ID", sn_id, TRUE);
+              if (sn_id)
+                {
+                  envp = g_environ_setenv (envp, "DESKTOP_STARTUP_ID", sn_id, TRUE);
+                  g_free (sn_id);
+                }
             }
 
           g_list_free_full (launched_files, g_object_unref);
@@ -2289,7 +2293,8 @@ g_desktop_app_info_make_platform_data (GDesktopAppInfo   *info,
           gchar *sn_id;
 
           sn_id = g_app_launch_context_get_startup_notify_id (launch_context, G_APP_INFO (info), launched_files);
-          g_variant_builder_add (&builder, "{sv}", "desktop-startup-id", g_variant_new_take_string (sn_id));
+          if (sn_id)
+            g_variant_builder_add (&builder, "{sv}", "desktop-startup-id", g_variant_new_take_string (sn_id));
         }
 
       g_list_free_full (launched_files, g_object_unref);