[gnome-photos] Fix the reference counting for NotificationManager



commit 17abe9aab78fee90ab45a0606860e07a81c30148
Author: Debarshi Ray <debarshir gnome org>
Date:   Sat Apr 2 00:19:14 2016 +0200

    Fix the reference counting for NotificationManager
    
    We were not finalizing NotificationManager when the main window is
    destroyed. Every call to photos_notification_manager_dup_singleton,
    except the first one, invoked both g_object_ref and g_object_ref_sink.
    This is wrong because it leaks a reference.
    
    NotificationManager is odd in the sense that it is a GInitiallyUnowned
    (because it is a GtkWidget) and a singleton at the same time. Let's
    ensure that notification_manager_dup_singleton always sinks the
    floating reference. This hides all the subtleties of floating
    references from the clients.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=763908

 src/photos-delete-notification.c   |    2 +-
 src/photos-done-notification.c     |    2 +-
 src/photos-embed.c                 |    2 +-
 src/photos-export-notification.c   |    2 +-
 src/photos-indexing-notification.c |    2 +-
 src/photos-notification-manager.c  |    3 +--
 src/photos-print-notification.c    |    2 +-
 7 files changed, 7 insertions(+), 8 deletions(-)
---
diff --git a/src/photos-delete-notification.c b/src/photos-delete-notification.c
index a6513cf..0c71ff6 100644
--- a/src/photos-delete-notification.c
+++ b/src/photos-delete-notification.c
@@ -226,7 +226,7 @@ photos_delete_notification_init (PhotosDeleteNotification *self)
   app = g_application_get_default ();
   state = photos_search_context_get_state (PHOTOS_SEARCH_CONTEXT (app));
 
-  self->ntfctn_mngr = g_object_ref_sink (photos_notification_manager_dup_singleton ());
+  self->ntfctn_mngr = photos_notification_manager_dup_singleton ();
   self->item_mngr = g_object_ref (state->item_mngr);
 }
 
diff --git a/src/photos-done-notification.c b/src/photos-done-notification.c
index 29efb0e..99d12d2 100644
--- a/src/photos-done-notification.c
+++ b/src/photos-done-notification.c
@@ -248,7 +248,7 @@ photos_done_notification_set_property (GObject *object, guint prop_id, const GVa
 static void
 photos_done_notification_init (PhotosDoneNotification *self)
 {
-  self->ntfctn_mngr = g_object_ref_sink (photos_notification_manager_dup_singleton ());
+  self->ntfctn_mngr = photos_notification_manager_dup_singleton ();
 }
 
 
diff --git a/src/photos-embed.c b/src/photos-embed.c
index 3b37a4c..f440832 100644
--- a/src/photos-embed.c
+++ b/src/photos-embed.c
@@ -679,7 +679,7 @@ photos_embed_init (PhotosEmbed *self)
   searchbar = photos_main_toolbar_get_searchbar (PHOTOS_MAIN_TOOLBAR (self->toolbar));
   g_signal_connect_swapped (searchbar, "activate-result", G_CALLBACK (photos_embed_activate_result), self);
 
-  self->ntfctn_mngr = g_object_ref_sink (photos_notification_manager_dup_singleton ());
+  self->ntfctn_mngr = photos_notification_manager_dup_singleton ();
   gtk_overlay_add_overlay (GTK_OVERLAY (self->stack_overlay), self->ntfctn_mngr);
 
   self->overview = photos_view_container_new (PHOTOS_WINDOW_MODE_OVERVIEW, _("Photos"));
diff --git a/src/photos-export-notification.c b/src/photos-export-notification.c
index aca2dc5..ff02eda 100644
--- a/src/photos-export-notification.c
+++ b/src/photos-export-notification.c
@@ -394,7 +394,7 @@ photos_export_notification_set_property (GObject *object, guint prop_id, const G
 static void
 photos_export_notification_init (PhotosExportNotification *self)
 {
-  self->ntfctn_mngr = g_object_ref_sink (photos_notification_manager_dup_singleton ());
+  self->ntfctn_mngr = photos_notification_manager_dup_singleton ();
 }
 
 
diff --git a/src/photos-indexing-notification.c b/src/photos-indexing-notification.c
index 8b3c2b6..12deac5 100644
--- a/src/photos-indexing-notification.c
+++ b/src/photos-indexing-notification.c
@@ -262,7 +262,7 @@ photos_indexing_notification_init (PhotosIndexingNotification *self)
       return;
     }
 
-  self->ntfctn_mngr = g_object_ref_sink (photos_notification_manager_dup_singleton ());
+  self->ntfctn_mngr = photos_notification_manager_dup_singleton ();
 
   self->spinner = gtk_spinner_new ();
   gtk_widget_set_size_request (self->spinner, 16, 16);
diff --git a/src/photos-notification-manager.c b/src/photos-notification-manager.c
index 5839c48..7635fc7 100644
--- a/src/photos-notification-manager.c
+++ b/src/photos-notification-manager.c
@@ -91,10 +91,9 @@ photos_notification_manager_constructor (GType type,
                                                                                      n_construct_params,
                                                                                      construct_params);
       g_object_add_weak_pointer (self, (gpointer) &self);
-      return self;
     }
 
-  return g_object_ref (self);
+  return g_object_ref_sink (self);
 }
 
 
diff --git a/src/photos-print-notification.c b/src/photos-print-notification.c
index beeeed9..7944c15 100644
--- a/src/photos-print-notification.c
+++ b/src/photos-print-notification.c
@@ -150,7 +150,7 @@ photos_print_notification_init (PhotosPrintNotification *self)
 {
   GtkWidget *image;
 
-  self->ntfctn_mngr = g_object_ref_sink (photos_notification_manager_dup_singleton ());
+  self->ntfctn_mngr = photos_notification_manager_dup_singleton ();
 
   self->spinner = gtk_spinner_new ();
   gtk_widget_set_size_request (self->spinner, 16, 16);


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