From b1dafe9a3173e1c0dd437e7b895e09993f37ba9e Mon Sep 17 00:00:00 2001 From: nick_m Date: Sat, 7 Feb 2015 23:33:09 +1100 Subject: [PATCH] Properly deallocate memory when clearing selection_op_history and before XMLNode*s. Improve some comments. --- gtk2_ardour/editor.cc | 27 ++++++++++++++++++++++----- libs/pbd/undo.cc | 2 +- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/gtk2_ardour/editor.cc b/gtk2_ardour/editor.cc index c8b3437662..a66972a7e9 100644 --- a/gtk2_ardour/editor.cc +++ b/gtk2_ardour/editor.cc @@ -3326,7 +3326,12 @@ Editor::begin_selection_op_history () { selection_op_cmd_depth = 0; selection_op_history_it = 0; - selection_op_history.clear(); + + while(!selection_op_history.empty()) { + delete selection_op_history.front(); + selection_op_history.pop_front(); + } + selection_undo_action->set_sensitive (false); selection_redo_action->set_sensitive (false); selection_op_history.push_front (&_selection_memento->get_state ()); @@ -3349,10 +3354,19 @@ Editor::commit_reversible_selection_op () if (selection_op_cmd_depth == 1) { if (selection_op_history_it > 0 && selection_op_history_it < selection_op_history.size()) { - /* the user has undone some selection ops and then made a new one */ + /** + The user has undone some selection ops and then made a new one, + making anything earlier in the list invalid. + */ + list::iterator it = selection_op_history.begin(); - advance (it, selection_op_history_it); - selection_op_history.erase (selection_op_history.begin(), it); + list::iterator e_it = it; + advance (e_it, selection_op_history_it); + + for ( ; it != e_it; ++it) { + delete *it; + } + selection_op_history.erase (selection_op_history.begin(), e_it); } selection_op_history.push_front (&_selection_memento->get_state ()); @@ -3432,7 +3446,10 @@ void Editor::abort_reversible_command () { if (_session) { - before.clear(); + while(!before.empty()) { + delete before.front(); + before.pop_front(); + } _session->abort_reversible_command (); } } diff --git a/libs/pbd/undo.cc b/libs/pbd/undo.cc index 2da9c7214d..182773ee49 100644 --- a/libs/pbd/undo.cc +++ b/libs/pbd/undo.cc @@ -220,7 +220,7 @@ UndoHistory::add (UndoTransaction* const ut) } UndoList.push_back (ut); - /* Adding a transacrion means that redo is meaningless from this point. */ + /* Adding a transacrion makes the redo list meaningless. */ _clearing = true; for (std::list::iterator i = RedoList.begin(); i != RedoList.end(); ++i) { delete *i;