Fix crash in wxCommandProcessor of capacity N when N-1 commands were undone.

Performing N commands (where N is the maximal number of commands stored by
wxCommandProcessor), undoing N-1 of them and performing another command
resulted in a crash because a dangling pointer was left.

Closes #12027.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@64245 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2010-05-07 23:38:31 +00:00
parent a104022931
commit 1544ba0edc

View File

@ -112,18 +112,6 @@ void wxCommandProcessor::Store(wxCommand *command)
{
wxCHECK_RET( command, wxT("no command in wxCommandProcessor::Store") );
if ( (int)m_commands.GetCount() == m_maxNoCommands )
{
wxList::compatibility_iterator firstNode = m_commands.GetFirst();
wxCommand *firstCommand = (wxCommand *)firstNode->GetData();
delete firstCommand;
m_commands.Erase(firstNode);
// Make sure m_lastSavedCommand won't point to freed memory
if ( m_lastSavedCommand == firstNode )
m_lastSavedCommand = wxList::compatibility_iterator();
}
// Correct a bug: we must chop off the current 'branch'
// so that we're at the end of the command list.
if (!m_currentCommand)
@ -145,6 +133,18 @@ void wxCommandProcessor::Store(wxCommand *command)
}
}
if ( (int)m_commands.GetCount() == m_maxNoCommands )
{
wxList::compatibility_iterator firstNode = m_commands.GetFirst();
wxCommand *firstCommand = (wxCommand *)firstNode->GetData();
delete firstCommand;
m_commands.Erase(firstNode);
// Make sure m_lastSavedCommand won't point to freed memory
if ( m_lastSavedCommand == firstNode )
m_lastSavedCommand = wxList::compatibility_iterator();
}
m_commands.Append(command);
m_currentCommand = m_commands.GetLast();
SetMenuStrings();