From fa3043a631a30b10c445e575f009e9e652ac8fa6 Mon Sep 17 00:00:00 2001 From: Christopher Lam Date: Mon, 26 Jun 2023 21:26:44 +0800 Subject: [PATCH] g_menu_item_new must be g_object_unreffed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Although gnome API usually insertions usually take ownership of the child element, in this case the GMenuItem attributes are copied into the GMenu. From https://docs.gtk.org/gio/method.Menu.insert_item.html -- * Description Inserts item into menu. The “insertion” is actually done by copying all of the attribute and link values of item and using them to form a new item within menu. As such, item itself is not really inserted, but rather, a menu item that is exactly the same as the one presently described by item. This means that item is essentially useless after the insertion occurs. Any changes you make to it are ignored unless it is inserted again (at which point its updated values will be copied). You should probably just free item once you’re done. There are many convenience functions to take care of common cases. See g_menu_insert(), g_menu_insert_section() and g_menu_insert_submenu() as well as “prepend” and “append” variants of each of these functions. Available since: 2.32 --- gnucash/gnome-utils/gnc-gtk-utils.c | 1 + gnucash/gnome-utils/gnc-main-window.cpp | 1 + gnucash/gnome-utils/gnc-plugin-file-history.c | 1 + gnucash/gnome-utils/gnc-plugin-menu-additions.c | 2 +- 4 files changed, 4 insertions(+), 1 deletion(-) diff --git a/gnucash/gnome-utils/gnc-gtk-utils.c b/gnucash/gnome-utils/gnc-gtk-utils.c index a023cd4b7f..c3c8fad1e8 100644 --- a/gnucash/gnome-utils/gnc-gtk-utils.c +++ b/gnucash/gnome-utils/gnc-gtk-utils.c @@ -907,6 +907,7 @@ gnc_menubar_model_update_item (GMenuModel *menu_model, const gchar *action_name, g_menu_remove (G_MENU(gsm->model), gsm->index); g_menu_insert_item (G_MENU(gsm->model), gsm->index, item); + g_object_unref (item); found = TRUE; } if (old_target) diff --git a/gnucash/gnome-utils/gnc-main-window.cpp b/gnucash/gnome-utils/gnc-main-window.cpp index e5b5f0929a..5dd830edf8 100644 --- a/gnucash/gnome-utils/gnc-main-window.cpp +++ b/gnucash/gnome-utils/gnc-main-window.cpp @@ -1820,6 +1820,7 @@ gnc_main_window_update_one_menu_action (GncMainWindow *window, if (pos < g_menu_model_get_n_items (gsm->model)) g_menu_remove (G_MENU(gsm->model), pos); g_menu_insert_item (G_MENU(gsm->model), pos, item); + g_object_unref (item); g_free (gsm); LEAVE(" "); diff --git a/gnucash/gnome-utils/gnc-plugin-file-history.c b/gnucash/gnome-utils/gnc-plugin-file-history.c index 45174ba0bb..6b2c435af0 100644 --- a/gnucash/gnome-utils/gnc-plugin-file-history.c +++ b/gnucash/gnome-utils/gnc-plugin-file-history.c @@ -459,6 +459,7 @@ gnc_history_update_action (GncMainWindow *window, g_free (full_action_name); g_free (label_name); g_free (tooltip); + g_object_unref (item); } g_free (gsm); g_free (action_name); diff --git a/gnucash/gnome-utils/gnc-plugin-menu-additions.c b/gnucash/gnome-utils/gnc-plugin-menu-additions.c index 98ef68cb9b..69051b8630 100644 --- a/gnucash/gnome-utils/gnc-plugin-menu-additions.c +++ b/gnucash/gnome-utils/gnc-plugin-menu-additions.c @@ -481,7 +481,7 @@ gnc_plugin_menu_additions_add_to_window (GncPlugin *plugin, menu_plugin->item_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); per_window.item_hash = menu_plugin->item_hash; - per_window.build_menu_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); + per_window.build_menu_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); per_window.report_menu = g_menu_new (); menu_list = g_slist_sort (gnc_extensions_get_menu_list(),