[gtk+] gtkplacesview: bail out if operation cancelled



commit 00b17651b1d00cdaf60c7d75fcd5fc4945812361
Author: Carlos Soriano <csoriano gnome org>
Date:   Fri Aug 21 19:57:07 2015 +0200

    gtkplacesview: bail out if operation cancelled
    
    When an operation is cancelled it's never safe to access
    the object itself or the private struct, since it could be
    called (and probably is) during finalize.
    
    In case the operation is cancelled, just bail out to fix
    the crashes.

 gtk/gtkplacesview.c |   42 +++++++++++++++++++++++++++---------------
 1 files changed, 27 insertions(+), 15 deletions(-)
---
diff --git a/gtk/gtkplacesview.c b/gtk/gtkplacesview.c
index 60ee5f6..f71e26c 100644
--- a/gtk/gtkplacesview.c
+++ b/gtk/gtkplacesview.c
@@ -1145,21 +1145,11 @@ server_mount_ready_cb (GObject      *source_file,
   GError *error;
   GFile *location;
 
-  view = GTK_PLACES_VIEW (user_data);
-  priv = gtk_places_view_get_instance_private (view);
   location = G_FILE (source_file);
   should_show = TRUE;
   error = NULL;
 
-  priv->should_pulse_entry = FALSE;
-  set_busy_cursor (view, FALSE);
-
   g_file_mount_enclosing_volume_finish (location, res, &error);
-  /* Restore from Cancel to Connect */
-  gtk_button_set_label (GTK_BUTTON (priv->connect_button), _("Con_nect"));
-  gtk_widget_set_sensitive (priv->address_entry, TRUE);
-  priv->connecting_to_server = FALSE;
-
   if (error)
     {
       should_show = FALSE;
@@ -1176,14 +1166,30 @@ server_mount_ready_cb (GObject      *source_file,
                (error->code != G_IO_ERROR_CANCELLED &&
                 error->code != G_IO_ERROR_FAILED_HANDLED))
         {
+          view = GTK_PLACES_VIEW (user_data);
           /* if it wasn't cancelled show a dialog */
           emit_show_error_message (view, _("Unable to access location"), error->message);
           should_show = FALSE;
         }
-
+      else
+        {
+          /* it was cancelled, so probably it was called during finalize, bail out. */
+          g_clear_error (&error);
+          return;
+        }
       g_clear_error (&error);
     }
 
+  view = GTK_PLACES_VIEW (user_data);
+  priv = gtk_places_view_get_instance_private (view);
+  priv->should_pulse_entry = FALSE;
+  set_busy_cursor (view, FALSE);
+
+  /* Restore from Cancel to Connect */
+  gtk_button_set_label (GTK_BUTTON (priv->connect_button), _("Con_nect"));
+  gtk_widget_set_sensitive (priv->address_entry, TRUE);
+  priv->connecting_to_server = FALSE;
+
   if (should_show)
     {
       server_list_add_server (view, location);
@@ -1234,14 +1240,10 @@ volume_mount_ready_cb (GObject      *source_volume,
   GVolume *volume;
   GError *error;
 
-  view = GTK_PLACES_VIEW (user_data);
-  priv = gtk_places_view_get_instance_private (view);
   volume = G_VOLUME (source_volume);
   should_show = TRUE;
   error = NULL;
 
-  set_busy_cursor (view, FALSE);
-
   g_volume_mount_finish (volume, res, &error);
 
   if (error)
@@ -1264,10 +1266,20 @@ volume_mount_ready_cb (GObject      *source_volume,
           emit_show_error_message (GTK_PLACES_VIEW (user_data), _("Unable to access location"), 
error->message);
           should_show = FALSE;
         }
+      else
+        {
+          /* it was cancelled, so probably it was called during finalize, bail out. */
+          g_clear_error (&error);
+          return;
+        }
 
       g_clear_error (&error);
     }
 
+  view = GTK_PLACES_VIEW (user_data);
+  priv = gtk_places_view_get_instance_private (view);
+  set_busy_cursor (view, FALSE);
+
   if (should_show)
     {
       GMount *mount;


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