- // GtkFileChooserButton will automatically destroy the
- // GtkFileChooserDialog associated with m_dialog.
- // Thus we have to set its m_widget to NULL to avoid
- // double destruction on same widget
- m_dialog->m_widget = NULL;
+ if ( m_dialog )
+ {
+ // We need to delete the C++ dialog object here but we shouldn't delete
+ // its widget which is used by our GtkFileChooserButton and will be
+ // deleted by it when it is itself destroyed in our base class dtor. So
+ // take the widget ownership away from the dialog to avoid GTK+ errors
+ // that would happen if GtkFileChooserButton tried to access the
+ // already destroyed dialog widget.
+ g_object_unref(m_dialog->m_widget);
+ m_dialog->m_widget = NULL;
+ delete m_dialog;
+ }