From f0f6c372802aabe7ba098d3af1f81cbc03eba27b Mon Sep 17 00:00:00 2001 From: Peter Eisenmann Date: Fri, 14 Apr 2023 22:18:58 +0000 Subject: [PATCH] files-view: Handle canceled clipboard update Correctly handle the cancellation of a clipboard update by checking the return value of gdk_clipboard_read_value_finish() and returning early on cancellation. Fixes: #2868 --- src/nautilus-files-view.c | 13 ++++++++++--- src/nautilus-list-base.c | 17 +++++++++++++---- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c index adce3f519..2d7ae526b 100644 --- a/src/nautilus-files-view.c +++ b/src/nautilus-files-view.c @@ -7210,8 +7210,8 @@ update_actions_clipboard_contents_received (GObject *source_object, GAsyncResult *res, gpointer user_data) { - NautilusFilesView *view = NAUTILUS_FILES_VIEW (user_data); - NautilusFilesViewPrivate *priv = nautilus_files_view_get_instance_private (view); + NautilusFilesView *view; + NautilusFilesViewPrivate *priv; NautilusClipboard *clip = NULL; gboolean can_link_from_copied_files; gboolean settings_show_create_link; @@ -7222,8 +7222,15 @@ update_actions_clipboard_contents_received (GObject *source_object, const GValue *value; value = gdk_clipboard_read_value_finish (GDK_CLIPBOARD (source_object), res, NULL); + if (value == NULL) + { + return; + } - if (value != NULL && G_VALUE_HOLDS (value, NAUTILUS_TYPE_CLIPBOARD)) + view = NAUTILUS_FILES_VIEW (user_data); + priv = nautilus_files_view_get_instance_private (view); + + if (G_VALUE_HOLDS (value, NAUTILUS_TYPE_CLIPBOARD)) { clip = g_value_get_boxed (value); } diff --git a/src/nautilus-list-base.c b/src/nautilus-list-base.c index 8d16c682e..5a1708c92 100644 --- a/src/nautilus-list-base.c +++ b/src/nautilus-list-base.c @@ -1302,15 +1302,24 @@ on_clipboard_contents_received (GObject *source_object, GAsyncResult *res, gpointer user_data) { - NautilusFilesView *files_view = NAUTILUS_FILES_VIEW (user_data); - NautilusListBase *self = NAUTILUS_LIST_BASE (files_view); - NautilusListBasePrivate *priv = nautilus_list_base_get_instance_private (self); + NautilusFilesView *files_view; + NautilusListBase *self; + NautilusListBasePrivate *priv; NautilusClipboard *clip; NautilusViewItem *item; const GValue *value; value = gdk_clipboard_read_value_finish (GDK_CLIPBOARD (source_object), res, NULL); + if (value == NULL) + { + return; + } + + files_view = NAUTILUS_FILES_VIEW (user_data); + self = NAUTILUS_LIST_BASE (files_view); + priv = nautilus_list_base_get_instance_private (self); + for (GList *l = priv->cut_files; l != NULL; l = l->next) { item = nautilus_view_model_get_item_from_file (priv->model, l->data); @@ -1321,7 +1330,7 @@ on_clipboard_contents_received (GObject *source_object, } g_clear_list (&priv->cut_files, g_object_unref); - if (value != NULL && G_VALUE_HOLDS (value, NAUTILUS_TYPE_CLIPBOARD)) + if (G_VALUE_HOLDS (value, NAUTILUS_TYPE_CLIPBOARD)) { clip = g_value_get_boxed (value); }