# HG changeset patch # User Daniel J Sebald # Date 1350189397 18000 # Node ID c9c79d4a0a004bb8309374771aa2596fcccee5b7 # Parent fb9dffe5fbfb4469f66becd0dab61f02b34d679f Delete dynamic objects in the main_window destructor for proper cleanup. (bug #37234) * main-window.h (main_window : public QMainWindow): Remove member variables that aren't utilized. * main-window.cc (main_window::~main_window): Delete all the objects created by the construct process that remain the ownership of the main_window. Ownership of some other objects are handed off elsewhere. diff -r fb9dffe5fbfb -r c9c79d4a0a00 libgui/src/main-window.cc --- a/libgui/src/main-window.cc Fri Nov 09 20:29:21 2012 -0700 +++ b/libgui/src/main-window.cc Sat Oct 13 23:36:37 2012 -0500 @@ -61,6 +61,36 @@ main_window::~main_window () { + // Clean up all dynamically created objects to ensure they are + // deleted before this main_window is. Otherwise, some will be + // attached to a non-existent parent. + + if (_octave_qt_event_listener) + delete _octave_qt_event_listener; + + if (_file_editor) + delete _file_editor; + + if (_terminal_dock_widget) + delete _terminal_dock_widget; + + if (_terminal) + delete _terminal; + + if (_status_bar) + delete _status_bar; + + if (_documentation_dock_widget) + delete _documentation_dock_widget; + + if (_files_dock_widget) + delete _files_dock_widget; + + if (_history_dock_widget) + delete _history_dock_widget; + + if (_workspace_view) + delete _workspace_view; } void @@ -485,11 +515,11 @@ _current_directory_combo_box->setMaxVisibleItems (16); _current_directory_combo_box->setMaxCount (16); - _current_directory_tool_button = new QToolButton (this); - _current_directory_tool_button->setIcon (QIcon(":/actions/icons/search.png")); + QToolButton *current_directory_tool_button = new QToolButton (this); + current_directory_tool_button->setIcon (QIcon(":/actions/icons/search.png")); - _current_directory_up_tool_button = new QToolButton (this); - _current_directory_up_tool_button->setIcon (QIcon(":/actions/icons/up.png")); + QToolButton *current_directory_up_tool_button = new QToolButton (this); + current_directory_up_tool_button->setIcon (QIcon(":/actions/icons/up.png")); // Octave Terminal subwindow. _terminal = new QTerminal (this); @@ -497,6 +527,9 @@ _terminal->setFocusPolicy (Qt::StrongFocus); _terminal_dock_widget = new terminal_dock_widget (_terminal, this); + // Create and set the central widget. QMainWindow takes ownership of + // the widget (pointer) so there is no need to delete the object upon + // destroying this main_window. QWidget *dummyWidget = new QWidget (); dummyWidget->setObjectName ("CentralDummyWidget"); dummyWidget->resize (10, 10); @@ -753,10 +786,12 @@ main_tool_bar->addAction (undo_action); main_tool_bar->addAction (redo_action); main_tool_bar->addSeparator (); + // addWidget takes ownership of the objects so there is no + // need to delete these upon destroying this main_window. main_tool_bar->addWidget (new QLabel (tr ("Current Directory:"))); main_tool_bar->addWidget (_current_directory_combo_box); - main_tool_bar->addWidget (_current_directory_tool_button); - main_tool_bar->addWidget (_current_directory_up_tool_button); + main_tool_bar->addWidget (current_directory_tool_button); + main_tool_bar->addWidget (current_directory_up_tool_button); connect (qApp, SIGNAL (aboutToQuit ()), this, SLOT (prepare_for_quit ())); @@ -836,9 +871,9 @@ this, SLOT (handle_load_workspace_request ())); connect (clear_workspace_action, SIGNAL (triggered ()), this, SLOT (handle_clear_workspace_request ())); - connect (_current_directory_tool_button, SIGNAL (clicked ()), + connect (current_directory_tool_button, SIGNAL (clicked ()), this, SLOT (change_current_working_directory ())); - connect (_current_directory_up_tool_button, SIGNAL (clicked ()), + connect (current_directory_up_tool_button, SIGNAL (clicked ()), this, SLOT (current_working_directory_up())); connect (copy_action, SIGNAL (triggered()), _terminal, SLOT (copyClipboard ())); diff -r fb9dffe5fbfb -r c9c79d4a0a00 libgui/src/main-window.h --- a/libgui/src/main-window.h Fri Nov 09 20:29:21 2012 -0700 +++ b/libgui/src/main-window.h Sat Oct 13 23:36:37 2012 -0500 @@ -166,8 +166,6 @@ // Toolbars. QStatusBar * _status_bar; QComboBox * _current_directory_combo_box; - QToolButton * _current_directory_tool_button; - QToolButton * _current_directory_up_tool_button; octave_qt_event_listener *_octave_qt_event_listener;