[totem] media-player-keys: Hold a ref to the plugin object during async operations



commit cb3299f89bc03bd128972c79b9c4b22120e6a5f9
Author: Philip Withnall <philip tecnocode co uk>
Date:   Fri Apr 8 14:44:06 2011 +0100

    media-player-keys: Hold a ref to the plugin object during async operations
    
    This prevents us using freed memory if the async operations during shutdown
    take too long.

 .../media-player-keys/totem-media-player-keys.c    |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)
---
diff --git a/src/plugins/media-player-keys/totem-media-player-keys.c b/src/plugins/media-player-keys/totem-media-player-keys.c
index 3c5f507..a6cd721 100644
--- a/src/plugins/media-player-keys/totem-media-player-keys.c
+++ b/src/plugins/media-player-keys/totem-media-player-keys.c
@@ -106,6 +106,8 @@ grab_media_player_keys_cb (GDBusProxy                 *proxy,
 		return;
 	}
 	g_variant_unref (variant);
+
+	g_object_unref (pi);
 }
 
 static void
@@ -130,7 +132,7 @@ grab_media_player_keys (TotemMediaPlayerKeysPlugin *pi)
 					  G_DBUS_CALL_FLAGS_NONE,
 					  -1, cancellable,
 					  (GAsyncReadyCallback) grab_media_player_keys_cb,
-					  pi);
+					  g_object_ref (pi));
 
 	/* GDBus keeps a reference throughout the async call */
 	g_object_unref (cancellable);
@@ -189,6 +191,8 @@ got_proxy_cb (GObject                    *source_object,
 
 	g_signal_connect (G_OBJECT (pi->priv->proxy), "g-signal",
 			  G_CALLBACK (key_pressed), pi);
+
+	g_object_unref (pi);
 }
 
 static void
@@ -211,7 +215,7 @@ name_appeared_cb (GDBusConnection            *connection,
 				  "org.gnome.SettingsDaemon.MediaKeys",
 				  cancellable,
 				  (GAsyncReadyCallback) got_proxy_cb,
-				  pi);
+				  g_object_ref (pi));
 
 	/* GDBus keeps a reference throughout the async call */
 	g_object_unref (cancellable);
@@ -244,7 +248,7 @@ impl_activate (PeasActivatable *plugin)
 					       G_BUS_NAME_WATCHER_FLAGS_NONE,
 					       (GBusNameAppearedCallback) name_appeared_cb,
 					       (GBusNameVanishedCallback) name_vanished_cb,
-					       pi, NULL);
+					       g_object_ref (pi), (GDestroyNotify) g_object_unref);
 
 	totem = g_object_get_data (G_OBJECT (plugin), "object");
 	window = totem_get_main_window (totem);



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