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.
This commit is contained in:
John Ralls 2023-04-20 20:08:38 -07:00
parent 50ff4a3af7
commit 4a5b897d89
2 changed files with 9 additions and 1 deletions

View File

@ -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);
}

View File

@ -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());