From d9f2f4442233952401f25b8c05f8a7282c9aa491 Mon Sep 17 00:00:00 2001 From: Theo Linkspfeifer Date: Fri, 8 May 2020 10:30:17 +0200 Subject: [PATCH] Prevent crash when trying to eject null device (Bug #13404) --- thunar/thunar-shortcuts-view.c | 60 ++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/thunar/thunar-shortcuts-view.c b/thunar/thunar-shortcuts-view.c index 1ff455fa..1150f6ee 100644 --- a/thunar/thunar-shortcuts-view.c +++ b/thunar/thunar-shortcuts-view.c @@ -1953,24 +1953,26 @@ thunar_shortcuts_view_eject (ThunarShortcutsView *view) { /* determine the device/mount for the shortcut at the given tree iterator */ gtk_tree_model_get (model, &iter, THUNAR_SHORTCUTS_MODEL_COLUMN_DEVICE, &device, -1); - _thunar_return_if_fail (THUNAR_IS_DEVICE (device)); - /* prepare a mount operation */ - mount_operation = thunar_gtk_mount_operation_new (GTK_WIDGET (view)); + if (G_LIKELY (device != NULL)) + { + /* prepare a mount operation */ + mount_operation = thunar_gtk_mount_operation_new (GTK_WIDGET (view)); - /* start the spinner */ - child_model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model)); - thunar_shortcuts_model_set_busy (THUNAR_SHORTCUTS_MODEL (child_model), device, TRUE); + /* start the spinner */ + child_model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model)); + thunar_shortcuts_model_set_busy (THUNAR_SHORTCUTS_MODEL (child_model), device, TRUE); - /* try to unmount */ - thunar_device_eject (device, - mount_operation, - NULL, - thunar_shortcuts_view_eject_finish, - g_object_ref (view)); + /* try to unmount */ + thunar_device_eject (device, + mount_operation, + NULL, + thunar_shortcuts_view_eject_finish, + g_object_ref (view)); - g_object_unref (G_OBJECT (device)); - g_object_unref (G_OBJECT (mount_operation)); + g_object_unref (G_OBJECT (device)); + g_object_unref (G_OBJECT (mount_operation)); + } } } @@ -2096,24 +2098,26 @@ thunar_shortcuts_view_unmount (ThunarShortcutsView *view) { /* determine the device/mount for the shortcut at the given tree iterator */ gtk_tree_model_get (model, &iter, THUNAR_SHORTCUTS_MODEL_COLUMN_DEVICE, &device, -1); - _thunar_return_if_fail (THUNAR_IS_DEVICE (device)); - /* prepare a mount operation */ - mount_operation = thunar_gtk_mount_operation_new (GTK_WIDGET (view)); + if (G_LIKELY (device != NULL)) + { + /* prepare a mount operation */ + mount_operation = thunar_gtk_mount_operation_new (GTK_WIDGET (view)); - /* start the spinner */ - child_model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model)); - thunar_shortcuts_model_set_busy (THUNAR_SHORTCUTS_MODEL (child_model), device, TRUE); + /* start the spinner */ + child_model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model)); + thunar_shortcuts_model_set_busy (THUNAR_SHORTCUTS_MODEL (child_model), device, TRUE); - /* try to unmount */ - thunar_device_unmount (device, - mount_operation, - NULL, - thunar_shortcuts_view_unmount_finish, - g_object_ref (view)); + /* try to unmount */ + thunar_device_unmount (device, + mount_operation, + NULL, + thunar_shortcuts_view_unmount_finish, + g_object_ref (view)); - g_object_unref (G_OBJECT (device)); - g_object_unref (G_OBJECT (mount_operation)); + g_object_unref (G_OBJECT (device)); + g_object_unref (G_OBJECT (mount_operation)); + } } } -- 2.26.2