Commit ebded163 authored by Dylan Smith's avatar Dylan Smith Committed by Alexandre Julliard

richedit: Fixed Valgrind error related to undoing.

The error was a memory access of a freed object. In ME_AddUndoItem I checked the top of the undo stack to end a coalescing undo transaction, assuming that this should be either a valid undo item, or NULL, instead it was already freed.
parent 5b2bdc06
...@@ -55,13 +55,7 @@ ME_UndoItem *ME_AddUndoItem(ME_TextEditor *editor, ME_DIType type, const ME_Disp ...@@ -55,13 +55,7 @@ ME_UndoItem *ME_AddUndoItem(ME_TextEditor *editor, ME_DIType type, const ME_Disp
return NULL; return NULL;
else else
{ {
ME_DisplayItem *pItem; ME_DisplayItem *pItem = (ME_DisplayItem *)ALLOC_OBJ(ME_UndoItem);
if (editor->pUndoStack
&& editor->pUndoStack->type == diUndoPotentialEndTransaction)
{
editor->pUndoStack->type = diUndoEndTransaction;
}
pItem = (ME_DisplayItem *)ALLOC_OBJ(ME_UndoItem);
((ME_UndoItem *)pItem)->nCR = ((ME_UndoItem *)pItem)->nLF = -1; ((ME_UndoItem *)pItem)->nCR = ((ME_UndoItem *)pItem)->nLF = -1;
switch(type) switch(type)
{ {
...@@ -109,6 +103,11 @@ ME_UndoItem *ME_AddUndoItem(ME_TextEditor *editor, ME_DIType type, const ME_Disp ...@@ -109,6 +103,11 @@ ME_UndoItem *ME_AddUndoItem(ME_TextEditor *editor, ME_DIType type, const ME_Disp
pItem->prev = NULL; pItem->prev = NULL;
if (editor->nUndoMode == umAddToUndo || editor->nUndoMode == umAddBackToUndo) if (editor->nUndoMode == umAddToUndo || editor->nUndoMode == umAddBackToUndo)
{ {
if (editor->pUndoStack
&& editor->pUndoStack->type == diUndoPotentialEndTransaction)
{
editor->pUndoStack->type = diUndoEndTransaction;
}
if (editor->nUndoMode == umAddToUndo) if (editor->nUndoMode == umAddToUndo)
TRACE("Pushing id=%s to undo stack, deleting redo stack\n", ME_GetDITypeName(type)); TRACE("Pushing id=%s to undo stack, deleting redo stack\n", ME_GetDITypeName(type));
else else
...@@ -355,17 +354,18 @@ BOOL ME_Undo(ME_TextEditor *editor) { ...@@ -355,17 +354,18 @@ BOOL ME_Undo(ME_TextEditor *editor) {
editor->nUndoMode = umAddToRedo; editor->nUndoMode = umAddToRedo;
p = editor->pUndoStack->next; p = editor->pUndoStack->next;
ME_DestroyDisplayItem(editor->pUndoStack); ME_DestroyDisplayItem(editor->pUndoStack);
editor->pUndoStack = p;
do { do {
ME_DisplayItem *pp = p; p->prev = NULL;
ME_PlayUndoItem(editor, p); ME_PlayUndoItem(editor, p);
p = p->next; editor->pUndoStack = p->next;
ME_DestroyDisplayItem(pp); ME_DestroyDisplayItem(p);
p = editor->pUndoStack;
} while(p && p->type != diUndoEndTransaction); } while(p && p->type != diUndoEndTransaction);
ME_AddUndoItem(editor, diUndoEndTransaction, NULL);
editor->pUndoStack = p;
editor->nUndoStackSize--;
if (p) if (p)
p->prev = NULL; p->prev = NULL;
ME_AddUndoItem(editor, diUndoEndTransaction, NULL);
editor->nUndoStackSize--;
editor->nUndoMode = nMode; editor->nUndoMode = nMode;
ME_UpdateRepaint(editor); ME_UpdateRepaint(editor);
return TRUE; return TRUE;
...@@ -389,16 +389,17 @@ BOOL ME_Redo(ME_TextEditor *editor) { ...@@ -389,16 +389,17 @@ BOOL ME_Redo(ME_TextEditor *editor) {
editor->nUndoMode = umAddBackToUndo; editor->nUndoMode = umAddBackToUndo;
p = editor->pRedoStack->next; p = editor->pRedoStack->next;
ME_DestroyDisplayItem(editor->pRedoStack); ME_DestroyDisplayItem(editor->pRedoStack);
editor->pRedoStack = p;
do { do {
ME_DisplayItem *pp = p; p->prev = NULL;
ME_PlayUndoItem(editor, p); ME_PlayUndoItem(editor, p);
p = p->next; editor->pRedoStack = p->next;
ME_DestroyDisplayItem(pp); ME_DestroyDisplayItem(p);
p = editor->pRedoStack;
} while(p && p->type != diUndoEndTransaction); } while(p && p->type != diUndoEndTransaction);
ME_AddUndoItem(editor, diUndoEndTransaction, NULL);
editor->pRedoStack = p;
if (p) if (p)
p->prev = NULL; p->prev = NULL;
ME_AddUndoItem(editor, diUndoEndTransaction, NULL);
editor->nUndoMode = nMode; editor->nUndoMode = nMode;
ME_UpdateRepaint(editor); ME_UpdateRepaint(editor);
return TRUE; return TRUE;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment