Fix #1248: Crash when hiding file list
authorColin Clark <colin.clark@cclark.uk>
Thu, 29 Feb 2024 10:05:11 +0000 (10:05 +0000)
committerColin Clark <colin.clark@cclark.uk>
Thu, 29 Feb 2024 10:05:11 +0000 (10:05 +0000)
https://github.com/BestImageViewer/geeqie/issues/1248

Fix problems resulting from 6d72bf GTK4: Reduce the use of
gtk_widget_destroy()

14 files changed:
src/bar-comment.cc
src/bar-exif.cc
src/bar.cc
src/collect-table.cc
src/image.cc
src/pan-view/pan-view-filter.cc
src/pan-view/pan-view-search.cc
src/preferences.cc
src/ui-misc.cc
src/ui-utildlg.cc
src/utilops.cc
src/view-dir.cc
src/view-file/view-file-icon.cc
src/view-file/view-file.cc

index ca724a9..8950501 100644 (file)
@@ -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);
index 795d6bf..47940a8 100644 (file)
@@ -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<GtkWidget *>(data);
-       g_object_unref(entry);
+       gtk_container_remove(GTK_CONTAINER(gtk_widget_get_parent(entry)), entry);
 }
 
 #if HAVE_GTK4
index a44bc78..bba0d9e 100644 (file)
 #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<GtkWidget *>(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<GDestroyNotify>(g_object_unref));
+       g_list_free_full(list, reinterpret_cast<GDestroyNotify>(remove_child_from_parent));
 }
 
 void bar_write_config(GtkWidget *bar, GString *outstr, gint indent)
index 8176629..9fcd7c1 100644 (file)
@@ -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);
index b2a45da..45af04d 100644 (file)
@@ -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);
index b21954b..42f649a 100644 (file)
@@ -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);
index f4f17bd..5247054 100644 (file)
@@ -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);
index 6e987e0..e37e912 100644 (file)
@@ -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)
index 6d67343..81973ff 100644 (file)
@@ -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;
 
index 80edddc..065ce9e 100644 (file)
@@ -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);
index 66081f1..9a241bb 100644 (file)
@@ -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)
index 8d28126..e5e688d 100644 (file)
@@ -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)
index b24b383..10caa67 100644 (file)
@@ -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;
 }
 
index 9639c4d..62b6ed1 100644 (file)
@@ -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)