1b60d7
--- a/shell/ev-media-player-keys.c
1b60d7
+++ b/shell/ev-media-player-keys.c
1b60d7
@@ -41,8 +41,9 @@ struct _EvMediaPlayerKeys
1b60d7
 {
1b60d7
 	GObject        parent;
1b60d7
 
1b60d7
-        GDBusProxy *proxy;
1b60d7
-	gboolean    has_name_owner;
1b60d7
+        GDBusProxy   *proxy;
1b60d7
+	gboolean      has_name_owner;
1b60d7
+	GCancellable *cancellable;
1b60d7
 };
1b60d7
 
1b60d7
 struct _EvMediaPlayerKeysClass
1b60d7
@@ -163,7 +164,7 @@ mediakeys_service_appeared_cb (GObject      *source_object,
1b60d7
 			       GAsyncResult *res,
1b60d7
 			       gpointer      user_data)
1b60d7
 {
1b60d7
-        EvMediaPlayerKeys *keys = EV_MEDIA_PLAYER_KEYS (user_data);
1b60d7
+	EvMediaPlayerKeys *keys;
1b60d7
 	GDBusProxy *proxy;
1b60d7
 
1b60d7
 	proxy = g_dbus_proxy_new_for_bus_finish (res, NULL);
1b60d7
@@ -172,6 +173,7 @@ mediakeys_service_appeared_cb (GObject      *source_object,
1b60d7
 		return;
1b60d7
 	}
1b60d7
 
1b60d7
+	keys = EV_MEDIA_PLAYER_KEYS (user_data);
1b60d7
 	g_signal_connect (proxy, "g-signal",
1b60d7
 			  G_CALLBACK (media_player_key_pressed_cb),
1b60d7
 			  keys);
1b60d7
@@ -187,13 +189,15 @@ mediakeys_service_appeared_cb (GObject      *source_object,
1b60d7
 static void
1b60d7
 ev_media_player_keys_init (EvMediaPlayerKeys *keys)
1b60d7
 {
1b60d7
+	keys->cancellable = g_cancellable_new ();
1b60d7
+
1b60d7
 	g_dbus_proxy_new_for_bus (G_BUS_TYPE_SESSION,
1b60d7
 				  G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
1b60d7
 				  NULL,
1b60d7
 				  SD_NAME,
1b60d7
 				  SD_OBJECT_PATH,
1b60d7
 				  SD_INTERFACE,
1b60d7
-				  NULL,
1b60d7
+				  keys->cancellable,
1b60d7
 				  mediakeys_service_appeared_cb,
1b60d7
 				  keys);
1b60d7
 }
1b60d7
@@ -212,6 +216,9 @@ ev_media_player_keys_finalize (GObject *object)
1b60d7
 {
1b60d7
 	EvMediaPlayerKeys *keys = EV_MEDIA_PLAYER_KEYS (object);
1b60d7
 
1b60d7
+	g_cancellable_cancel (keys->cancellable);
1b60d7
+	g_object_unref (keys->cancellable);
1b60d7
+
1b60d7
         if (keys->proxy != NULL) {
1b60d7
 		ev_media_player_keys_release_keys (keys);
1b60d7
                 g_object_unref (keys->proxy);