From: Colin Clark Date: Thu, 29 Feb 2024 10:05:11 +0000 (+0000) Subject: Fix #1248: Crash when hiding file list X-Git-Tag: v2.3~15 X-Git-Url: http://geeqie.org/cgi-bin/gitweb.cgi?p=geeqie.git;a=commitdiff_plain;h=439fc96a603c140926de30d2fa7f1b85e1e40905 Fix #1248: Crash when hiding file list https://github.com/BestImageViewer/geeqie/issues/1248 Fix problems resulting from 6d72bf GTK4: Reduce the use of gtk_widget_destroy() --- diff --git a/src/bar-comment.cc b/src/bar-comment.cc index ca724a98..8950501b 100644 --- a/src/bar-comment.cc +++ b/src/bar-comment.cc @@ -257,7 +257,7 @@ static void bar_pane_comment_destroy(GtkWidget *, gpointer data) file_data_unregister_notify_func(bar_pane_comment_notify_cb, pcd); #if HAVE_SPELL - g_object_unref(pcd->gspell_view); + gtk_container_remove(GTK_CONTAINER(gtk_widget_get_parent(pcd->comment_view)), pcd->comment_view); #endif file_data_unref(pcd->fd); g_free(pcd->key); diff --git a/src/bar-exif.cc b/src/bar-exif.cc index 795d6bf5..47940a8f 100644 --- a/src/bar-exif.cc +++ b/src/bar-exif.cc @@ -133,7 +133,10 @@ static void bar_pane_exif_setup_entry_box(PaneExifData *ped, ExifEntry *ee) gboolean horizontal = !ee->editable; gboolean editable = ee->editable; - if (ee->box) g_object_unref(ee->box); + if (ee->box) + { + gtk_container_remove(GTK_CONTAINER(gtk_widget_get_parent(ee->box)), ee->box); + } ee->box = horizontal ? gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0) : gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); gq_gtk_container_add(GTK_WIDGET(ee->ebox), ee->box); @@ -618,7 +621,7 @@ static void bar_pane_exif_conf_dialog_cb(GtkWidget *, gpointer data) static void bar_pane_exif_delete_entry_cb(GtkWidget *, gpointer data) { auto entry = static_cast(data); - g_object_unref(entry); + gtk_container_remove(GTK_CONTAINER(gtk_widget_get_parent(entry)), entry); } #if HAVE_GTK4 diff --git a/src/bar.cc b/src/bar.cc index a44bc78f..bba0d9e3 100644 --- a/src/bar.cc +++ b/src/bar.cc @@ -40,6 +40,17 @@ #include "ui-menu.h" #include "ui-misc.h" + +namespace +{ + +void remove_child_from_parent(gpointer data) +{ + gtk_container_remove(GTK_CONTAINER(gtk_widget_get_parent(GTK_WIDGET(data))), GTK_WIDGET(data)); +} + +} + struct KnownPanes { PaneType type; @@ -285,7 +296,7 @@ static void height_spin_key_press_cb(GtkEventControllerKey *, gint keyval, guint { if ((keyval == GDK_KEY_Return || keyval == GDK_KEY_Escape)) { - g_object_unref(GTK_WIDGET(data)); + gq_gtk_widget_destroy(GTK_WIDGET(data)); } } @@ -351,7 +362,7 @@ static void bar_expander_height_cb(GtkWidget *, gpointer data) static void bar_expander_delete_cb(GtkWidget *, gpointer data) { auto expander = static_cast(data); - g_object_unref(expander); + gtk_container_remove(GTK_CONTAINER(gtk_widget_get_parent(expander)), expander); } static void bar_expander_add_cb(GtkWidget *widget, gpointer) @@ -599,7 +610,7 @@ void bar_clear(GtkWidget *bar) list = gtk_container_get_children(GTK_CONTAINER(bd->vbox)); - g_list_free_full(list, reinterpret_cast(g_object_unref)); + g_list_free_full(list, reinterpret_cast(remove_child_from_parent)); } void bar_write_config(GtkWidget *bar, GString *outstr, gint indent) diff --git a/src/collect-table.cc b/src/collect-table.cc index 81766292..9fcd7c10 100644 --- a/src/collect-table.cc +++ b/src/collect-table.cc @@ -2662,7 +2662,7 @@ static void collection_table_destroy(GtkWidget *, gpointer data) { g_signal_handlers_disconnect_matched(G_OBJECT(ct->popup), G_SIGNAL_MATCH_DATA, 0, 0, nullptr, nullptr, ct); - g_object_unref(ct->popup); + gq_gtk_widget_destroy(ct->popup); } if (ct->sync_idle_id) g_source_remove(ct->sync_idle_id); diff --git a/src/image.cc b/src/image.cc index b2a45da2..45af04d0 100644 --- a/src/image.cc +++ b/src/image.cc @@ -2177,7 +2177,7 @@ void image_set_frame(ImageWindow *imd, gboolean frame) if (imd->frame) { gtk_container_remove(GTK_CONTAINER(imd->frame), imd->pr); - g_object_unref(imd->frame); + gtk_container_remove(GTK_CONTAINER(imd->widget), imd->frame); imd->frame = nullptr; } gq_gtk_box_pack_start(GTK_BOX(imd->widget), imd->pr, TRUE, TRUE, 0); diff --git a/src/pan-view/pan-view-filter.cc b/src/pan-view/pan-view-filter.cc index b21954b0..42f649a6 100644 --- a/src/pan-view/pan-view-filter.cc +++ b/src/pan-view/pan-view-filter.cc @@ -152,7 +152,7 @@ static void pan_filter_kw_button_cb(GtkButton *widget, gpointer data) /** @todo (xsdg): Fix filter element pointed object memory leak. */ ui->filter_elements = g_list_delete_link(ui->filter_elements, cb_state->filter_element); - g_object_unref(GTK_WIDGET(widget)); + gtk_container_remove(GTK_CONTAINER(gtk_widget_get_parent(GTK_WIDGET(widget))), GTK_WIDGET(widget)); g_free(cb_state); pan_filter_status(pw, _("Removed keyword…")); @@ -235,7 +235,7 @@ void pan_filter_toggle_cb(GtkWidget *button, gpointer data) parent = gtk_widget_get_parent(ui->filter_button_arrow); - g_object_unref(ui->filter_button_arrow); + gtk_container_remove(GTK_CONTAINER(parent), ui->filter_button_arrow); ui->filter_button_arrow = gtk_image_new_from_icon_name(GQ_ICON_PAN_UP, GTK_ICON_SIZE_BUTTON); gq_gtk_box_pack_start(GTK_BOX(parent), ui->filter_button_arrow, FALSE, FALSE, 0); @@ -249,7 +249,7 @@ void pan_filter_toggle_cb(GtkWidget *button, gpointer data) parent = gtk_widget_get_parent(ui->filter_button_arrow); - g_object_unref(ui->filter_button_arrow); + gtk_container_remove(GTK_CONTAINER(parent), ui->filter_button_arrow); ui->filter_button_arrow = gtk_image_new_from_icon_name(GQ_ICON_PAN_DOWN, GTK_ICON_SIZE_BUTTON); gq_gtk_box_pack_start(GTK_BOX(parent), ui->filter_button_arrow, FALSE, FALSE, 0); diff --git a/src/pan-view/pan-view-search.cc b/src/pan-view/pan-view-search.cc index f4f17bdd..5247054b 100644 --- a/src/pan-view/pan-view-search.cc +++ b/src/pan-view/pan-view-search.cc @@ -444,7 +444,7 @@ void pan_search_toggle_cb(GtkWidget *button, gpointer data) parent = gtk_widget_get_parent(ui->search_button_arrow); - g_object_unref(ui->search_button_arrow); + gtk_container_remove(GTK_CONTAINER(parent), ui->search_button_arrow); ui->search_button_arrow = gtk_image_new_from_icon_name(GQ_ICON_PAN_UP, GTK_ICON_SIZE_BUTTON); gq_gtk_box_pack_start(GTK_BOX(parent), ui->search_button_arrow, FALSE, FALSE, 0); @@ -458,7 +458,7 @@ void pan_search_toggle_cb(GtkWidget *button, gpointer data) parent = gtk_widget_get_parent(ui->search_button_arrow); - g_object_unref(ui->search_button_arrow); + gtk_container_remove(GTK_CONTAINER(parent), ui->search_button_arrow); ui->search_button_arrow = gtk_image_new_from_icon_name(GQ_ICON_PAN_DOWN, GTK_ICON_SIZE_BUTTON); gq_gtk_box_pack_start(GTK_BOX(parent), ui->search_button_arrow, FALSE, FALSE, 0); diff --git a/src/preferences.cc b/src/preferences.cc index 6e987e02..e37e9126 100644 --- a/src/preferences.cc +++ b/src/preferences.cc @@ -1509,7 +1509,7 @@ static void font_response_cb(GtkDialog *dialog, gint response_id, gpointer) g_free(font); } - g_object_unref(dialog); + gq_gtk_widget_destroy(GTK_WIDGET(dialog)); } static void image_overlay_set_font_cb(GtkWidget *widget, gpointer) @@ -1554,7 +1554,7 @@ static void text_color_response_cb(GtkDialog *dialog, gint response_id, gpointer c_options->image_overlay.text_alpha = color.alpha * 255; } - g_object_unref(dialog); + gq_gtk_widget_destroy(GTK_WIDGET(dialog)); } static void image_overlay_set_text_color_cb(GtkWidget *widget, gpointer) diff --git a/src/ui-misc.cc b/src/ui-misc.cc index 6d673437..81973ff8 100644 --- a/src/ui-misc.cc +++ b/src/ui-misc.cc @@ -814,7 +814,7 @@ static void date_selection_popup_hide(DateSelection *ds) gtk_widget_hide(ds->window); - g_object_unref(ds->window); + gq_gtk_widget_destroy(ds->window); ds->window = nullptr; ds->calendar = nullptr; diff --git a/src/ui-utildlg.cc b/src/ui-utildlg.cc index 80edddc4..065ce9e7 100644 --- a/src/ui-utildlg.cc +++ b/src/ui-utildlg.cc @@ -553,7 +553,7 @@ static gboolean appimage_notification_close_cb(gpointer data) if (appimage_data->window) { - g_object_unref(appimage_data->window); + gq_gtk_widget_destroy(appimage_data->window); } g_thread_pool_free(appimage_data->thread_pool, TRUE, TRUE); diff --git a/src/utilops.cc b/src/utilops.cc index 66081f1b..9a241bba 100644 --- a/src/utilops.cc +++ b/src/utilops.cc @@ -2005,8 +2005,7 @@ static void file_util_warn_op_in_progress(const gchar *title) static void file_util_details_dialog_close_cb(GtkWidget *, gpointer data) { - g_object_unref(GTK_WIDGET(data)); - + gq_gtk_widget_destroy(GTK_WIDGET(data)); } static void file_util_details_dialog_destroy_cb(GtkWidget *widget, gpointer data) diff --git a/src/view-dir.cc b/src/view-dir.cc index 8d281268..e5e688d0 100644 --- a/src/view-dir.cc +++ b/src/view-dir.cc @@ -143,7 +143,7 @@ static void vd_destroy_cb(GtkWidget *widget, gpointer data) { g_signal_handlers_disconnect_matched(G_OBJECT(vd->popup), G_SIGNAL_MATCH_DATA, 0, 0, nullptr, nullptr, vd); - g_object_unref(vd->popup); + gq_gtk_widget_destroy(vd->popup); } switch (vd->type) diff --git a/src/view-file/view-file-icon.cc b/src/view-file/view-file-icon.cc index b24b3834..10caa67a 100644 --- a/src/view-file/view-file-icon.cc +++ b/src/view-file/view-file-icon.cc @@ -385,7 +385,7 @@ static void tip_show(ViewFile *vf) static void tip_hide(ViewFile *vf) { - if (VFICON(vf)->tip_window) g_object_unref(VFICON(vf)->tip_window); + if (VFICON(vf)->tip_window) gq_gtk_widget_destroy(VFICON(vf)->tip_window); VFICON(vf)->tip_window = nullptr; } diff --git a/src/view-file/view-file.cc b/src/view-file/view-file.cc index 9639c4dc..62b6ed1f 100644 --- a/src/view-file/view-file.cc +++ b/src/view-file/view-file.cc @@ -837,7 +837,7 @@ static void vf_destroy_cb(GtkWidget *widget, gpointer data) { g_signal_handlers_disconnect_matched(G_OBJECT(vf->popup), G_SIGNAL_MATCH_DATA, 0, 0, nullptr, nullptr, vf); - g_object_unref(vf->popup); + gq_gtk_widget_destroy(vf->popup); } if (vf->read_metadata_in_idle_id)