gnucash stable: Bug 798863 - Crash on clicking Settings button second time
John Ralls
jralls at code.gnucash.org
Thu Apr 20 23:12:26 EDT 2023
Updated via https://github.com/Gnucash/gnucash/commit/4a5b897d (commit)
from https://github.com/Gnucash/gnucash/commit/50ff4a3a (commit)
commit 4a5b897d8918c1a22ed0da5b6be1daf5a6b41b50
Author: John Ralls <jralls at ceridwen.us>
Date: Thu Apr 20 20:08:38 2023 -0700
Bug 798863 - Crash on clicking Settings button second time
Ensure that dialog resources stored in options are freed when the
dialog is destroyed.
The crash happened when a new dialog replaced the old one on the options
and the old one's destructors tried to access a dangling reference to
a GtkWidget.
diff --git a/gnucash/gnome-utils/dialog-options.cpp b/gnucash/gnome-utils/dialog-options.cpp
index af93d9822a..16e51920da 100644
--- a/gnucash/gnome-utils/dialog-options.cpp
+++ b/gnucash/gnome-utils/dialog-options.cpp
@@ -629,6 +629,13 @@ GncOptionsDialog::~GncOptionsDialog()
gnc_unregister_gui_component_by_data(m_component_class, this);
g_signal_handlers_disconnect_by_func(m_window, (gpointer)dialog_destroy_cb, this);
g_signal_handlers_disconnect_by_func(m_window, (gpointer)dialog_window_key_press_cb, this);
+ m_option_db->foreach_section([](GncOptionSectionPtr& section)
+ {
+ section->foreach_option([](GncOption& option)
+ {
+ option.set_ui_item(std::unique_ptr<GncOptionUIItem>(nullptr));
+ });
+ });
g_object_unref(m_window);
}
diff --git a/libgnucash/engine/gnc-option.cpp b/libgnucash/engine/gnc-option.cpp
index f43fd778d3..49fa74e73a 100644
--- a/libgnucash/engine/gnc-option.cpp
+++ b/libgnucash/engine/gnc-option.cpp
@@ -221,7 +221,8 @@ GncOption::set_ui_item(GncOptionUIItemPtr&& ui_item)
return option.get_ui_type();
}, *m_option);
- if (ui_item->get_ui_type() != opt_ui_type)
+ //ui_item may be nullptr to free the old m_ui_item.
+ if (ui_item && ui_item->get_ui_type() != opt_ui_type)
{
PERR("Setting option %s:%s UI element failed, mismatched UI types.",
get_section().c_str(), get_name().c_str());
Summary of changes:
gnucash/gnome-utils/dialog-options.cpp | 7 +++++++
libgnucash/engine/gnc-option.cpp | 3 ++-
2 files changed, 9 insertions(+), 1 deletion(-)
More information about the gnucash-changes
mailing list