From da5ddccfdfcef7a0030dd1da2ea3a2f5cf8327e4 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Fri, 19 Nov 2021 17:15:13 +0200 Subject: [PATCH 13/13] gtk: Unref ref protecting widgets from destruction in editinfobox_refresh() See osdn #43222 Signed-off-by: Marko Lindqvist --- client/gui-gtk-2.0/editgui.c | 15 +++++++++++++++ client/gui-gtk-2.0/editgui.h | 4 +++- client/gui-gtk-2.0/gui_main.c | 6 ++++++ client/gui-gtk-3.0/editgui.c | 8 ++++++++ client/gui-gtk-3.0/gui_main.c | 5 +++++ client/gui-gtk-3.22/editgui.c | 8 ++++++++ client/gui-gtk-3.22/gui_main.c | 5 +++++ 7 files changed, 50 insertions(+), 1 deletion(-) diff --git a/client/gui-gtk-2.0/editgui.c b/client/gui-gtk-2.0/editgui.c index fd09f44590..aeb0da0b39 100644 --- a/client/gui-gtk-2.0/editgui.c +++ b/client/gui-gtk-2.0/editgui.c @@ -1884,3 +1884,18 @@ void editgui_notify_object_created(int tag, int id) pe = editprop_get_property_editor(); property_editor_handle_object_created(pe, tag, id); } + +/**************************************************************************** + Free resources allocated for the editgui. +****************************************************************************/ +void editgui_free(void) +{ + 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); + } +} diff --git a/client/gui-gtk-2.0/editgui.h b/client/gui-gtk-2.0/editgui.h index fb4907e891..e84fa50c4d 100644 --- a/client/gui-gtk-2.0/editgui.h +++ b/client/gui-gtk-2.0/editgui.h @@ -1,4 +1,4 @@ -/********************************************************************** +/*********************************************************************** Freeciv - Copyright (C) 2005 - The Freeciv Project This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -64,4 +64,6 @@ void editgui_create_widgets(void); struct editbar *editgui_get_editbar(void); struct editinfobox *editgui_get_editinfobox(void); +void editgui_free(void); + #endif /* FC__EDITGUI_H */ diff --git a/client/gui-gtk-2.0/gui_main.c b/client/gui-gtk-2.0/gui_main.c index b151c04a68..e67578320e 100644 --- a/client/gui-gtk-2.0/gui_main.c +++ b/client/gui-gtk-2.0/gui_main.c @@ -1690,6 +1690,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(); @@ -1700,6 +1705,7 @@ void ui_main(int argc, char **argv) diplomacy_dialog_done(); cma_fe_done(); free_unit_table(); + editgui_free(); gtk_widget_destroy(toplevel_tabs); gtk_widget_destroy(toplevel); message_buffer = NULL; /* Result of destruction of everything */ diff --git a/client/gui-gtk-3.0/editgui.c b/client/gui-gtk-3.0/editgui.c index 761d09affb..981ad2f766 100644 --- a/client/gui-gtk-3.0/editgui.c +++ b/client/gui-gtk-3.0/editgui.c @@ -1833,6 +1833,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.0/gui_main.c b/client/gui-gtk-3.0/gui_main.c index 494a347112..96ad745bcf 100644 --- a/client/gui-gtk-3.0/gui_main.c +++ b/client/gui-gtk-3.0/gui_main.c @@ -1831,6 +1831,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-3.22/editgui.c b/client/gui-gtk-3.22/editgui.c index f0ea3ee4c3..757208267b 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 3d723c3f4b..83391d0148 100644 --- a/client/gui-gtk-3.22/gui_main.c +++ b/client/gui-gtk-3.22/gui_main.c @@ -1918,6 +1918,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(); -- 2.33.0