[gnome-settings-daemon/gnome-3-22] media-keys: Reference count MediaKey struct instances



commit 00759eb2ca10e5f6681fe68ce183e39d7fe9dbbc
Author: Rui Matos <tiagomatos gmail com>
Date:   Mon Feb 13 20:19:32 2017 +0100

    media-keys: Reference count MediaKey struct instances
    
    https://bugzilla.gnome.org/show_bug.cgi?id=758302

 plugins/media-keys/gsd-media-keys-manager.c |   26 ++++++++++++++++++++++----
 1 files changed, 22 insertions(+), 4 deletions(-)
---
diff --git a/plugins/media-keys/gsd-media-keys-manager.c b/plugins/media-keys/gsd-media-keys-manager.c
index 14d3567..b3adcaf 100644
--- a/plugins/media-keys/gsd-media-keys-manager.c
+++ b/plugins/media-keys/gsd-media-keys-manager.c
@@ -126,6 +126,8 @@ typedef struct {
 } MediaPlayer;
 
 typedef struct {
+        gint ref_count;
+
         MediaKeyType key_type;
         ShellActionMode modes;
         const char *settings_key;
@@ -235,15 +237,31 @@ static gpointer manager_object = NULL;
 
 
 static void
-media_key_free (MediaKey *key)
+media_key_unref (MediaKey *key)
 {
         if (key == NULL)
                 return;
+        if (!g_atomic_int_dec_and_test (&key->ref_count))
+                return;
         g_free (key->custom_path);
         g_free (key->custom_command);
         g_free (key);
 }
 
+static MediaKey *
+media_key_ref (MediaKey *key)
+{
+        g_atomic_int_inc (&key->ref_count);
+        return key;
+}
+
+static MediaKey *
+media_key_new (void)
+{
+        MediaKey *key = g_new0 (MediaKey, 1);
+        return media_key_ref (key);
+}
+
 static void
 set_launch_context_env (GsdMediaKeysManager *manager,
                        GAppLaunchContext   *launch_context)
@@ -593,7 +611,7 @@ media_key_new_for_path (GsdMediaKeysManager *manager,
         }
         g_free (binding);
 
-        key = g_new0 (MediaKey, 1);
+        key = media_key_new ();
         key->key_type = CUSTOM_KEY;
         key->modes = GSD_ACTION_MODE_LAUNCHER;
         key->custom_path = g_strdup (path);
@@ -694,7 +712,7 @@ add_key (GsdMediaKeysManager *manager, guint i)
 {
        MediaKey *key;
 
-       key = g_new0 (MediaKey, 1);
+       key = media_key_new ();
        key->key_type = media_keys[i].key_type;
        key->settings_key = media_keys[i].settings_key;
        key->hard_coded = media_keys[i].hard_coded;
@@ -2777,7 +2795,7 @@ start_media_keys_idle_cb (GsdMediaKeysManager *manager)
         g_debug ("Starting media_keys manager");
         gnome_settings_profile_start (NULL);
 
-        manager->priv->keys = g_ptr_array_new_with_free_func ((GDestroyNotify) media_key_free);
+        manager->priv->keys = g_ptr_array_new_with_free_func ((GDestroyNotify) media_key_unref);
 
         initialize_volume_handler (manager);
 


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