From e63a066ced2afce06402c48467a150acb284d13b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Wed, 12 Apr 2023 00:41:20 +0200 Subject: [PATCH] gtk/dialogs: Destroy the window promptly on finish async function Some bindings (GJS!) could add temporary references to the GAsyncResult argument that we return, and thus to the GTask, which may cause the dialog not to close when the finish function is called (but at garbage collection instead!). To prevent this, just manually destroy the window (by removing the task data), so that we are not bound to the GTask lifetime anymore. Closes: https://gitlab.gnome.org/GNOME/gtk/-/issues/5741 --- gtk/gtkalertdialog.c | 3 +++ gtk/gtkcolordialog.c | 3 +++ gtk/gtkfiledialog.c | 15 +++++++++++++++ gtk/gtkfontdialog.c | 11 +++++++++++ 4 files changed, 32 insertions(+) diff --git a/gtk/gtkalertdialog.c b/gtk/gtkalertdialog.c index 33ccac37d9..efb4ed4a64 100644 --- a/gtk/gtkalertdialog.c +++ b/gtk/gtkalertdialog.c @@ -747,6 +747,9 @@ gtk_alert_dialog_choose_finish (GtkAlertDialog *self, g_return_val_if_fail (g_task_is_valid (result, self), -1); g_return_val_if_fail (g_task_get_source_tag (G_TASK (result)) == gtk_alert_dialog_choose, -1); + /* Destroy the dialog window not to be bound to GTask lifecycle */ + g_task_set_task_data (G_TASK (result), NULL, NULL); + return (int) g_task_propagate_int (G_TASK (result), error); } diff --git a/gtk/gtkcolordialog.c b/gtk/gtkcolordialog.c index d93c68ad3f..a6e69be7e9 100644 --- a/gtk/gtkcolordialog.c +++ b/gtk/gtkcolordialog.c @@ -492,6 +492,9 @@ gtk_color_dialog_choose_rgba_finish (GtkColorDialog *self, g_return_val_if_fail (g_task_is_valid (result, self), NULL); g_return_val_if_fail (g_task_get_source_tag (G_TASK (result)) == gtk_color_dialog_choose_rgba, NULL); + /* Destroy the dialog window not to be bound to GTask lifecycle */ + g_task_set_task_data (G_TASK (result), NULL, NULL); + return g_task_propagate_pointer (G_TASK (result), error); } diff --git a/gtk/gtkfiledialog.c b/gtk/gtkfiledialog.c index 8b9fc21a6a..b267e2d239 100644 --- a/gtk/gtkfiledialog.c +++ b/gtk/gtkfiledialog.c @@ -976,6 +976,9 @@ gtk_file_dialog_open_finish (GtkFileDialog *self, g_return_val_if_fail (g_task_is_valid (result, self), NULL); g_return_val_if_fail (g_task_get_source_tag (G_TASK (result)) == gtk_file_dialog_open, NULL); + /* Destroy the dialog window not to be bound to GTask lifecycle */ + g_task_set_task_data (G_TASK (result), NULL, NULL); + return finish_file_op (self, G_TASK (result), error); } @@ -1050,6 +1053,9 @@ gtk_file_dialog_select_folder_finish (GtkFileDialog *self, g_return_val_if_fail (g_task_is_valid (result, self), NULL); g_return_val_if_fail (g_task_get_source_tag (G_TASK (result)) == gtk_file_dialog_select_folder, NULL); + /* Destroy the dialog window not to be bound to GTask lifecycle */ + g_task_set_task_data (G_TASK (result), NULL, NULL); + return finish_file_op (self, G_TASK (result), error); } @@ -1120,6 +1126,9 @@ gtk_file_dialog_save_finish (GtkFileDialog *self, g_return_val_if_fail (g_task_is_valid (result, self), NULL); g_return_val_if_fail (g_task_get_source_tag (G_TASK (result)) == gtk_file_dialog_save, NULL); + /* Destroy the dialog window not to be bound to GTask lifecycle */ + g_task_set_task_data (G_TASK (result), NULL, NULL); + return finish_file_op (self, G_TASK (result), error); } @@ -1194,6 +1203,9 @@ gtk_file_dialog_open_multiple_finish (GtkFileDialog *self, g_return_val_if_fail (g_task_is_valid (result, self), NULL); g_return_val_if_fail (g_task_get_source_tag (G_TASK (result)) == gtk_file_dialog_open_multiple, NULL); + /* Destroy the dialog window not to be bound to GTask lifecycle */ + g_task_set_task_data (G_TASK (result), NULL, NULL); + return finish_multiple_files_op (self, G_TASK (result), error); } @@ -1268,6 +1280,9 @@ gtk_file_dialog_select_multiple_folders_finish (GtkFileDialog *self, g_return_val_if_fail (g_task_is_valid (result, self), NULL); g_return_val_if_fail (g_task_get_source_tag (G_TASK (result)) == gtk_file_dialog_select_multiple_folders, NULL); + /* Destroy the dialog window not to be bound to GTask lifecycle */ + g_task_set_task_data (G_TASK (result), NULL, NULL); + return finish_multiple_files_op (self, G_TASK (result), error); } diff --git a/gtk/gtkfontdialog.c b/gtk/gtkfontdialog.c index 878456d94d..c533dac2cc 100644 --- a/gtk/gtkfontdialog.c +++ b/gtk/gtkfontdialog.c @@ -697,6 +697,9 @@ gtk_font_dialog_choose_family_finish (GtkFontDialog *self, g_return_val_if_fail (g_task_is_valid (result, self), NULL); g_return_val_if_fail (g_task_get_source_tag (G_TASK (result)) == gtk_font_dialog_choose_family, NULL); + /* Destroy the dialog window not to be bound to GTask lifecycle */ + g_task_set_task_data (G_TASK (result), NULL, NULL); + return g_task_propagate_pointer (G_TASK (result), error); } @@ -777,6 +780,9 @@ gtk_font_dialog_choose_face_finish (GtkFontDialog *self, g_return_val_if_fail (g_task_is_valid (result, self), NULL); g_return_val_if_fail (g_task_get_source_tag (G_TASK (result)) == gtk_font_dialog_choose_face, NULL); + /* Destroy the dialog window not to be bound to GTask lifecycle */ + g_task_set_task_data (G_TASK (result), NULL, NULL); + return g_task_propagate_pointer (G_TASK (result), error); } @@ -855,6 +861,9 @@ gtk_font_dialog_choose_font_finish (GtkFontDialog *self, g_return_val_if_fail (g_task_is_valid (result, self), NULL); g_return_val_if_fail (g_task_get_source_tag (G_TASK (result)) == gtk_font_dialog_choose_font, NULL); + /* Destroy the dialog window not to be bound to GTask lifecycle */ + g_task_set_task_data (G_TASK (result), NULL, NULL); + return g_task_propagate_pointer (G_TASK (result), error); } @@ -944,6 +953,8 @@ gtk_font_dialog_choose_font_and_features_finish (GtkFontDialog *self, g_return_val_if_fail (g_task_is_valid (result, self), FALSE); g_return_val_if_fail (g_task_get_source_tag (G_TASK (result)) == gtk_font_dialog_choose_font_and_features, FALSE); + /* Destroy the dialog window not to be bound to GTask lifecycle */ + g_task_set_task_data (G_TASK (result), NULL, NULL); font_result = g_task_propagate_pointer (G_TASK (result), error); if (font_result) -- 2.30.2