Skip to content

Commit

Permalink
Bug 798863 - Crash on clicking Settings button second time
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jralls committed Apr 21, 2023
1 parent 50ff4a3 commit 4a5b897
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
7 changes: 7 additions & 0 deletions gnucash/gnome-utils/dialog-options.cpp
Expand Up @@ -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);
}

Expand Down
3 changes: 2 additions & 1 deletion libgnucash/engine/gnc-option.cpp
Expand Up @@ -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());
Expand Down

0 comments on commit 4a5b897

Please sign in to comment.