[Xfce4-commits] r29915 - in thunar/branches/migration-to-gio: . thunar

Jannis Pohlmann jannis at xfce.org
Wed Apr 29 18:28:21 CEST 2009


Author: jannis
Date: 2009-04-29 16:28:21 +0000 (Wed, 29 Apr 2009)
New Revision: 29915

Modified:
   thunar/branches/migration-to-gio/ChangeLog
   thunar/branches/migration-to-gio/thunar/thunar-shortcuts-view.c
Log:
	* thunar/thunar-shortcuts-view.c: Avoid segfaults due to an invalid
	  GtkTreeSelection being used in thunar_shortcuts_view_open_selection()
	  and thunar_shortcuts_view_open_selection_in_new_window(). This can
	  happen when the shortcuts view is essentially being destroyed but a
	  reference to it is still being kept for the mount/unmount/eject
	  handler. Increase the reference counter before passing the view to
	  asynchronous mount/unmount/eject functions and release the reference
	  in the handler.

Modified: thunar/branches/migration-to-gio/ChangeLog
===================================================================
--- thunar/branches/migration-to-gio/ChangeLog	2009-04-29 16:24:19 UTC (rev 29914)
+++ thunar/branches/migration-to-gio/ChangeLog	2009-04-29 16:28:21 UTC (rev 29915)
@@ -1,5 +1,16 @@
 2009-04-29	Jannis Pohlmann <jannis at xfce.org>
 
+	* thunar/thunar-shortcuts-view.c: Avoid segfaults due to an invalid
+	  GtkTreeSelection being used in thunar_shortcuts_view_open_selection()
+	  and thunar_shortcuts_view_open_selection_in_new_window(). This can
+	  happen when the shortcuts view is essentially being destroyed but a
+	  reference to it is still being kept for the mount/unmount/eject
+	  handler. Increase the reference counter before passing the view to
+	  asynchronous mount/unmount/eject functions and release the reference
+	  in the handler.
+
+2009-04-29	Jannis Pohlmann <jannis at xfce.org>
+
 	* thunar/thunar-shortcuts-model.c: In thunar_shortcuts_model_init()
 	  don't increase the reference counter on the volumes, otherwise we'd
 	  leak them here.

Modified: thunar/branches/migration-to-gio/thunar/thunar-shortcuts-view.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-shortcuts-view.c	2009-04-29 16:24:19 UTC (rev 29914)
+++ thunar/branches/migration-to-gio/thunar/thunar-shortcuts-view.c	2009-04-29 16:28:21 UTC (rev 29915)
@@ -1267,6 +1267,12 @@
 
   /* determine the selected item */
   selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
+
+  /* avoid dealing with invalid selections (may occur when the mount_finish()
+   * handler is called and the shortcuts view has been hidden already) */
+  if (!GTK_IS_TREE_SELECTION (selection))
+    return;
+
   if (gtk_tree_selection_get_selected (selection, &model, &iter))
     {
       /* determine the file for the shortcut at the given tree iterator */
@@ -1327,6 +1333,12 @@
 
   /* determine the selected item */
   selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
+
+  /* avoid dealing with invalid selections (may occur when the mount_finish()
+   * handler is called and the shortcuts view has been hidden already) */
+  if (!GTK_IS_TREE_SELECTION (selection))
+    return;
+
   if (gtk_tree_selection_get_selected (selection, &model, &iter))
     {
       /* determine the volume for the shortcut at the given tree iterator */
@@ -1392,6 +1404,8 @@
           g_error_free (error);
         }
     }
+
+  g_object_unref (view);
 }
 
 
@@ -1427,6 +1441,8 @@
           g_error_free (error);
         }
     }
+
+  g_object_unref (view);
 }
 
 
@@ -1437,7 +1453,6 @@
   GtkTreeSelection *selection;
   GtkTreeModel     *model;
   GtkTreeIter       iter;
-  GtkWidget        *window;
   GVolume          *volume;
   GMount           *mount;
 
@@ -1451,15 +1466,13 @@
       gtk_tree_model_get (model, &iter, THUNAR_SHORTCUTS_MODEL_COLUMN_VOLUME, &volume, -1);
       if (G_UNLIKELY (volume != NULL))
         {
-          /* determine the toplevel window */
-          window = gtk_widget_get_toplevel (GTK_WIDGET (view));
-
           /* determine what the appropriate method is: eject or unmount */
           if (g_volume_can_eject (volume))
             {
               /* try to to eject the volume asynchronously */
               g_volume_eject (volume, G_MOUNT_UNMOUNT_NONE, NULL, 
-                              thunar_shortcuts_view_eject_finish, view);
+                              thunar_shortcuts_view_eject_finish, 
+                              g_object_ref (view));
             }
           else
             {
@@ -1469,7 +1482,8 @@
                 {
                   /* the volume is mounted, try to unmount the mount */
                   g_mount_unmount (mount, G_MOUNT_UNMOUNT_NONE, NULL,
-                                   thunar_shortcuts_view_unmount_finish, view);
+                                   thunar_shortcuts_view_unmount_finish, 
+                                   g_object_ref (view));
 
                   /* release the mount */
                   g_object_unref (mount);
@@ -1511,8 +1525,11 @@
   /* check if there was an error */
   if (!g_volume_mount_finish (volume, result, &error))
     {
-      /* ignore GIO errors already handled */
-      if (error->domain != G_IO_ERROR || error->code != G_IO_ERROR_FAILED_HANDLED)
+      /* ignore GIO already handled errors or errors due to pending mount actions */
+      if (error->domain != G_IO_ERROR 
+          || (error->code != G_IO_ERROR_FAILED_HANDLED 
+              && error->code != G_IO_ERROR_ALREADY_MOUNTED
+              && error->code != G_IO_ERROR_PENDING))
         {
           window = gtk_widget_get_toplevel (GTK_WIDGET (view));
 
@@ -1529,6 +1546,8 @@
     {
       thunar_shortcuts_view_open_selection (view);
     }
+
+  g_object_unref (view);
 }
 
 
@@ -1550,8 +1569,11 @@
   /* check if there was an error */
   if (!g_volume_mount_finish (volume, result, &error))
     {
-      /* ignore GIO errors which were already handled */
-      if (error->domain != G_IO_ERROR || error->code != G_IO_ERROR_FAILED_HANDLED)
+      /* ignore GIO already handled errors or errors due to pending mount actions */
+      if (error->domain != G_IO_ERROR 
+          || (error->code != G_IO_ERROR_FAILED_HANDLED 
+              && error->code != G_IO_ERROR_ALREADY_MOUNTED
+              && error->code != G_IO_ERROR_PENDING))
         {
           window = gtk_widget_get_toplevel (GTK_WIDGET (view));
 
@@ -1568,6 +1590,8 @@
     {
       thunar_shortcuts_view_open_selection_in_new_window (view);
     }
+
+  g_object_unref (view);
 }
 
 
@@ -1613,12 +1637,14 @@
               if (open_in_new_window)
                 {
                   g_volume_mount (volume, G_MOUNT_MOUNT_NONE, mount_operation, NULL,
-                                  thunar_shortcuts_view_mount_new_window_finish, view);
+                                  thunar_shortcuts_view_mount_new_window_finish, 
+                                  g_object_ref (view));
                 }
               else
                 {
                   g_volume_mount (volume, G_MOUNT_MOUNT_NONE, mount_operation, NULL,
-                                  thunar_shortcuts_view_mount_finish, view);
+                                  thunar_shortcuts_view_mount_finish, 
+                                  g_object_ref (view));
                 }
 
               /* release the mount operation */




More information about the Xfce4-commits mailing list