From 7cc97bc9a593813ae0e8cc43fb664366d4114819 Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Fri, 19 Nov 2021 17:00:40 +0200
Subject: [PATCH 39/39] gtk: Unref ref protecting widgets from destruction in
 editinfobox_refresh()

See osdn #43222

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 client/gui-gtk-3.22/editgui.c  | 8 ++++++++
 client/gui-gtk-3.22/gui_main.c | 5 +++++
 client/gui-gtk-4.0/editgui.c   | 8 ++++++++
 client/gui-gtk-4.0/gui_main.c  | 5 +++++
 4 files changed, 26 insertions(+)

diff --git a/client/gui-gtk-3.22/editgui.c b/client/gui-gtk-3.22/editgui.c
index dd69a6f2b1..f5600ed7c9 100644
--- a/client/gui-gtk-3.22/editgui.c
+++ b/client/gui-gtk-3.22/editgui.c
@@ -1832,6 +1832,14 @@ void editgui_create_widgets(void)
 void editgui_free(void)
 {
   struct editbar *eb = editgui_get_editbar();
+  struct editinfobox *ei = editgui_get_editinfobox();
+
+  if (ei != NULL) {
+    /* We have extra ref for ei->widget that has protected
+     * it from getting destroyed when editinfobox_refresh()
+     * moves widgets around. Free that extra ref here. */
+    g_object_unref(ei->widget);
+  }
 
   clear_tool_stores(eb);
 }
diff --git a/client/gui-gtk-3.22/gui_main.c b/client/gui-gtk-3.22/gui_main.c
index 2a8392b1e7..b1c3d866ae 100644
--- a/client/gui-gtk-3.22/gui_main.c
+++ b/client/gui-gtk-3.22/gui_main.c
@@ -1935,6 +1935,11 @@ void ui_main(int argc, char **argv)
   gtk_main();
   gui_up = FALSE;
 
+  /* We have extra ref for unit_info_box that has protected
+   * it from getting destroyed when editinfobox_refresh()
+   * moves widgets around. Free that extra ref here. */
+  g_object_unref(unit_info_box);
+
   destroy_server_scans();
   free_mapcanvas_and_overview();
   spaceship_dialog_done();
diff --git a/client/gui-gtk-4.0/editgui.c b/client/gui-gtk-4.0/editgui.c
index 5a9be39ffb..8ca9ce7f2c 100644
--- a/client/gui-gtk-4.0/editgui.c
+++ b/client/gui-gtk-4.0/editgui.c
@@ -1879,6 +1879,14 @@ void editgui_create_widgets(void)
 void editgui_free(void)
 {
   struct editbar *eb = editgui_get_editbar();
+  struct editinfobox *ei = editgui_get_editinfobox();
+
+  if (ei != NULL) {
+    /* We have extra ref for ei->widget that has protected
+     * it from getting destroyed when editinfobox_refresh()
+     * moves widgets around. Free that extra ref here. */
+    g_object_unref(ei->widget);
+  }
 
   clear_tool_stores(eb);
 }
diff --git a/client/gui-gtk-4.0/gui_main.c b/client/gui-gtk-4.0/gui_main.c
index 4e44c20cff..c20f4948d8 100644
--- a/client/gui-gtk-4.0/gui_main.c
+++ b/client/gui-gtk-4.0/gui_main.c
@@ -1797,6 +1797,11 @@ void ui_main(int argc, char **argv)
   g_application_run(G_APPLICATION(fc_app), 0, NULL);
   gui_up = FALSE;
 
+  /* We have extra ref for unit_info_box that has protected
+   * it from getting destroyed when editinfobox_refresh()
+   * moves widgets around. Free that extra ref here. */
+  g_object_unref(unit_info_box);
+
   destroy_server_scans();
   free_mapcanvas_and_overview();
   spaceship_dialog_done();
-- 
2.33.0