[gnome-software/wip/rancell/apt: 1/2] Disconnect GNetworkMonitor::network-changed handlers when objects disposed.



commit 279bc80995da0700087e042b3acfee7c6896965e
Author: Robert Ancell <robert ancell canonical com>
Date:   Fri Mar 4 10:42:50 2016 +1300

    Disconnect GNetworkMonitor::network-changed handlers when objects disposed.
    
    Since GNOME Software can run in the background and GNetworkMonitor is a
    singleton this can cause the handlers to run on destroyed objects.

 src/gs-application.c   |    9 +++++++--
 src/gs-shell-updates.c |   11 ++++++++---
 2 files changed, 15 insertions(+), 5 deletions(-)
---
diff --git a/src/gs-application.c b/src/gs-application.c
index e811a15..9768c57 100644
--- a/src/gs-application.c
+++ b/src/gs-application.c
@@ -62,6 +62,7 @@ struct _GsApplication {
 #endif
        GsShellSearchProvider *search_provider;
        GNetworkMonitor *network_monitor;
+       gulong           network_changed_handler;
        GSettings       *settings;
 };
 
@@ -181,8 +182,8 @@ gs_application_monitor_network (GsApplication *app)
                return;
        app->network_monitor = g_object_ref (network_monitor);
 
-       g_signal_connect (app->network_monitor, "network-changed",
-                         G_CALLBACK (network_changed_cb), app);
+       app->network_changed_handler = g_signal_connect (app->network_monitor, "network-changed",
+                                                        G_CALLBACK (network_changed_cb), app);
 
        network_changed_cb (app->network_monitor,
                            g_network_monitor_get_network_available (app->network_monitor),
@@ -698,6 +699,10 @@ gs_application_dispose (GObject *object)
        g_clear_object (&app->provider);
        g_clear_object (&app->update_monitor);
        g_clear_object (&app->profile);
+       if (app->network_changed_handler != 0) {
+               g_signal_handler_disconnect (app->network_monitor, app->network_changed_handler);
+               app->network_changed_handler = 0;
+       }
        g_clear_object (&app->network_monitor);
 #ifdef HAVE_PACKAGEKIT
        g_clear_object (&app->dbus_helper);
diff --git a/src/gs-shell-updates.c b/src/gs-shell-updates.c
index b09b612..c75716d 100644
--- a/src/gs-shell-updates.c
+++ b/src/gs-shell-updates.c
@@ -65,6 +65,7 @@ struct _GsShellUpdates
        gboolean                 in_progress;
        GsShell                 *shell;
        GNetworkMonitor         *network_monitor;
+       gulong                   network_changed_handler;
        GsPluginStatus           last_status;
        GsShellUpdatesState      state;
        gboolean                 has_agreed_to_mobile_data;
@@ -1152,9 +1153,9 @@ gs_shell_updates_setup (GsShellUpdates *self,
        gs_shell_updates_monitor_permission (self);
 
        if (self->network_monitor != NULL) {
-               g_signal_connect (self->network_monitor, "network-changed",
-                                 G_CALLBACK (gs_shell_updates_notify_network_state_cb),
-                                 self);
+               self->network_changed_handler = g_signal_connect (self->network_monitor, "network-changed",
+                                               G_CALLBACK (gs_shell_updates_notify_network_state_cb),
+                                               self);
        }
 
        /* chain up */
@@ -1172,6 +1173,10 @@ gs_shell_updates_dispose (GObject *object)
 {
        GsShellUpdates *self = GS_SHELL_UPDATES (object);
 
+       if (self->network_changed_handler != 0) {
+               g_signal_handler_disconnect (self->network_monitor, self->network_changed_handler);
+               self->network_changed_handler = 0;
+       }
        if (self->cancellable_refresh != NULL) {
                g_cancellable_cancel (self->cancellable_refresh);
                g_clear_object (&self->cancellable_refresh);


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